From db5a0d5419cdbfc8c02f9e46318897787415c629 Mon Sep 17 00:00:00 2001 From: Chris Wisdo Date: Mon, 15 Jul 2019 14:18:07 -0400 Subject: [PATCH] Fixes select2 bug from RegEx escaped values Escaped values are needed for tablesorter filter, but unescaped values should be used in other contexts. (e.g., "a or b", "a/b") --- js/widgets/widget-filter-formatter-select2.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js/widgets/widget-filter-formatter-select2.js b/js/widgets/widget-filter-formatter-select2.js index 4a6816b6..65669de2 100644 --- a/js/widgets/widget-filter-formatter-select2.js +++ b/js/widgets/widget-filter-formatter-select2.js @@ -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');