Modify

Opened 7 years ago

Closed 7 years ago

#13296 closed defect (fixed)

spurious multiple space characters

Reported by: c.feige@… Owned by: Ryan J Ollos
Priority: normal Component: TracKeywordsPlugin
Severity: minor Keywords:
Cc: Trac Release: 1.0

Description

It can happen that the TracKeywordsPlugin inserts multiple space characters when clicking multiple times on the same keyword.

I have tested this plugin (TracKeywordsPlugin 0.3dev-r0 / revision r16858) with TRAC 1.0.4.

Reproduce

  1. click first keyword to insert
  2. click second keyword to insert
  3. click second keyword to removed
  4. repeat clicking on second keyword to insert / removed.

Each (repeated) remove operation leaves one extra space character in the keyword field. These spaces accumulate more and more.

Patch

I have modified the last line of the addTag JS-function and improved the whitespace cleanup. Previously it was only one Regex (el.value = newval.replace(/^\s+/, '');).

Improved version:

function addTag(w) {
    var el = document.getElementById(field_id);
    var orig = el.value;
    var newval = orig.replace(new RegExp('\\b' + w + '\\b'), '');
    var link = document.getElementById('add_' + w);
    if (orig != newval) {
        // remove tag.
        if(link) link.className = '';
    } else {
        newval = orig + (orig ? ' ' : '') + w;
        if(link) link.className = 'sel';
    }
    /*BUGFIX below this line: */
    newval = newval.replace(/^\s+/, '');/*remove leading whitespace*/
    newval = newval.replace(/\s+$/, '');/*remove trailing whitespace*/
    newval = newval.replace(/\s{2,}/, ' ');/*remove multiple whitespace*/
    el.value = newval;
}

Thanks Clemens

Attachments (0)

Change History (4)

comment:1 Changed 7 years ago by Ryan J Ollos

Reporter: changed from anonymous to c.feige@…

comment:2 Changed 7 years ago by Ryan J Ollos

Owner: set to Ryan J Ollos
Status: newaccepted

comment:3 Changed 7 years ago by Ryan J Ollos

Please consider providing a patch file in the future, to ease review (TracDev/SubmittingPatches).

comment:4 Changed 7 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 16865:

TracKeywordsPlugin 0.3dev: Strip trailing whitespace

Fixes #13296.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.