Skip to content

Commit

Permalink
Filter: partially revert df1afcc (see #1505)
Browse files Browse the repository at this point in the history
Automatic escaping of RegExp special characters must be done
manually as already explained in the documentation
  • Loading branch information
Mottie committed Jan 30, 2018
1 parent 18410a3 commit 25eb3f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/example-widget-filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ <h3><a href="#">Localization</a></h3>
<h3>Notes</h3>
<ul>
<li><span class="label label-info">Info</span> These changes still require the user to enter spaces in the filter to perform the search, e.g. <code>1 à 10</code> (shows rows with numbers between 1 and 10).</li>
<li><span class="label label-info">Info</span> Extra spaces around the value will be trimmed and it is valid to set a value to an empty string; but this won't disable the filter type (use `-` for "to", `|` for "or" and "&&" for "and").</li>
<li>
<span class="label warning">Warning</span> These language values are added to a regular expression using <code>new RegExp()</code>:
<ul>
Expand Down
18 changes: 9 additions & 9 deletions js/widgets/widget-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@
var options, string, txt, $header, column, val, fxn, noSelect,
c = table.config,
wo = c.widgetOptions,
escRegExp = function(prefix, str, suffix) {
str = str.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
processStr = function(prefix, str, suffix) {
str = str.trim();
// don't include prefix/suffix if str is empty
return str === '' ? '' : (prefix || '') + str + (suffix || '');
};
Expand All @@ -388,13 +388,13 @@
$.extend( tsfRegex, {
child : new RegExp( c.cssChildRow ),
filtered : new RegExp( wo.filter_filteredRow ),
alreadyFiltered : new RegExp( '(\\s+(-' + escRegExp('|', ts.language.or) + escRegExp('|', ts.language.to) + ')\\s+)', 'i' ),
toTest : new RegExp( '\\s+(-' + escRegExp('|', ts.language.to) + ')\\s+', 'i' ),
toSplit : new RegExp( '(?:\\s+(?:-' + escRegExp('|', ts.language.to) + ')\\s+)', 'gi' ),
andTest : new RegExp( '\\s+(' + escRegExp('', ts.language.and, '|') + '&&)\\s+', 'i' ),
andSplit : new RegExp( '(?:\\s+(?:' + escRegExp('', ts.language.and, '|') + '&&)\\s+)', 'gi' ),
orTest : new RegExp( '(\\|' + escRegExp('|\\s+', ts.language.or, '\\s+') + ')', 'i' ),
orSplit : new RegExp( '(?:\\|' + escRegExp('|\\s+(?:', ts.language.or, ')\\s+') + ')', 'gi' ),
alreadyFiltered : new RegExp( '(\\s+(-' + processStr('|', ts.language.or) + processStr('|', ts.language.to) + ')\\s+)', 'i' ),
toTest : new RegExp( '\\s+(-' + processStr('|', ts.language.to) + ')\\s+', 'i' ),
toSplit : new RegExp( '(?:\\s+(?:-' + processStr('|', ts.language.to) + ')\\s+)', 'gi' ),
andTest : new RegExp( '\\s+(' + processStr('', ts.language.and, '|') + '&&)\\s+', 'i' ),
andSplit : new RegExp( '(?:\\s+(?:' + processStr('', ts.language.and, '|') + '&&)\\s+)', 'gi' ),
orTest : new RegExp( '(\\|' + processStr('|\\s+', ts.language.or, '\\s+') + ')', 'i' ),
orSplit : new RegExp( '(?:\\|' + processStr('|\\s+(?:', ts.language.or, ')\\s+') + ')', 'gi' ),
iQuery : new RegExp( val, 'i' ),
igQuery : new RegExp( val, 'ig' ),
operTest : /^[<>]=?/,
Expand Down

0 comments on commit 25eb3f1

Please sign in to comment.