From df1afccddac6b4cfe9f4a10c694a8b7001247c7d Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Tue, 30 Jan 2018 12:48:09 -0600 Subject: [PATCH] Filter: Clean & escape language settings. See #1505 --- js/widgets/widget-filter.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 4af9a963..6a889cad 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -367,7 +367,12 @@ var options, string, txt, $header, column, val, fxn, noSelect, c = table.config, - wo = c.widgetOptions; + wo = c.widgetOptions, + escRegExp = function(prefix, str, suffix) { + str = str.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + // don't include prefix/suffix if str is empty + return str === '' ? '' : (prefix || '') + str + (suffix || ''); + }; c.$table.addClass( 'hasFilters' ); c.lastSearch = []; @@ -383,13 +388,13 @@ $.extend( tsfRegex, { child : new RegExp( c.cssChildRow ), filtered : new RegExp( wo.filter_filteredRow ), - alreadyFiltered : new RegExp( '(\\s+(' + ts.language.or + '|-|' + ts.language.to + ')\\s+)', 'i' ), - toTest : new RegExp( '\\s+(-|' + ts.language.to + ')\\s+', 'i' ), - toSplit : new RegExp( '(?:\\s+(?:-|' + ts.language.to + ')\\s+)', 'gi' ), - andTest : new RegExp( '\\s+(' + ts.language.and + '|&&)\\s+', 'i' ), - andSplit : new RegExp( '(?:\\s+(?:' + ts.language.and + '|&&)\\s+)', 'gi' ), - orTest : new RegExp( '(\\||\\s+' + ts.language.or + '\\s+)', 'i' ), - orSplit : new RegExp( '(?:\\s+(?:' + ts.language.or + ')\\s+|\\|)', 'gi' ), + 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' ), iQuery : new RegExp( val, 'i' ), igQuery : new RegExp( val, 'ig' ), operTest : /^[<>]=?/,