Opened 5 years ago

Last modified 5 years ago

#13534 closed enhancement

better separator handling and case-insensitive — at Initial Version

Reported by: clemens Owned by:
Priority: normal Component: TracKeywordsPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.2

Description

Hello

I propose and provide some moderate improvements to the trac_keywords.js file of the TracKeywordsPlugin.

Summary

  1. allow arbitrary keyword separators
  2. better handling for multiple spaces and separators
  3. keyword matching is case-insensitive
  4. avoid duplicate insertion of keyword section
  5. add some comments

Patch

Separators

The idea is not only to allow separation of keywords by SPACE and coma as previously, but also semi-colon, dash etc. I make use of the \W regex term to match all "non-word" characters as separators.

My changes also provide better handling in cases where multiple separators are used, for example bla,,,,blo.

Case-insensitive

The previous version did not consider a keyword if the case did not match, i.e. it was case-sensitive. One can discuss about it, but for me it is more useable and convenient if it behaves case-insensitive. The keywords BLA, bla, Bla and bLa should be treated as the same.

I am aware that other people may not share my opinion and might like to have case-sensitive. In this case it is easy to have a case-sensitive code variant. Look for my code comments about case-insensitive and `toLowerCase and remove the corresponding code.

Avoid Duplicates

I added a simple check to avoid duplicate insertion of the keyword section. This is because I came across a duplicate when I used the browser "save"-feature. The saved HTML page ended up having with two keyword sections (one was static HTML, the other dynamic from JS). My simple check avoids this.

Test case

The following test case uses:

  • upper and lower case keywords
  • numbers and letters
  • different separators
  • multiple separators
  • trailing separators

power, Other A2, C3, double double more double, slave;radio,.+/:other     eol-----epa.....

Clemens

Change History (2)

Changed 5 years ago by clemens

Attachment: trac_keywords.js added

updated source code

Changed 5 years ago by clemens

Attachment: trac_keywords_20190214.diff added

patch file

Note: See TracTickets for help on using tickets.