Skip to content

Commit

Permalink
Fixes select2 bug from RegEx escaped values
Browse files Browse the repository at this point in the history
Escaped values are needed for tablesorter filter, but unescaped values should be used in other contexts. (e.g., "a or b", "a/b")
  • Loading branch information
cwisdo authored and Mottie committed Dec 1, 2019
1 parent 9475a7c commit db5a0d5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions js/widgets/widget-filter-formatter-select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@
v = v.join('\u0000');
}
// escape special regex characters (http://stackoverflow.com/a/9310752/145346)
v = v.replace(/[-[\]{}()*+?.,/\\^$|#]/g, '\\$&');
var v_escape = v.replace(/[-[\]{}()*+?.,/\\^$|#]/g, '\\$&');
// convert string back into an array
if (arry) {
v = v.split('\u0000');
v_escape = v_escape.split('\u0000');
}
if (!ts.isEmptyObject($cell.find('.select2').data())) {
$input
// add regex, so we filter exact numbers
.val(
$.isArray(v) && v.length && v.join('') !== '' ?
'/(' + matchPrefix + (v || []).join(matchSuffix + '|' + matchPrefix) + matchSuffix + ')/' + flags :
$.isArray(v_escape) && v_escape.length && v_escape.join('') !== '' ?
'/(' + matchPrefix + (v_escape || []).join(matchSuffix + '|' + matchPrefix) + matchSuffix + ')/' + flags :
''
)
.trigger('search');
Expand Down

0 comments on commit db5a0d5

Please sign in to comment.