Skip to content

Commit 1201ad2

Browse files
prx-lmomportuga
authored andcommitted
[hotfix/6360]
- updated escapeRegExp - now escapes term first, before changing * - changed to greedy
1 parent 63e49b1 commit 1201ad2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/core/src/js/services/rowSearcher.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
var module = angular.module('ui.grid');
44

55
function escapeRegExp(str) {
6-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
6+
// based on https://github.com/sindresorhus/escape-string-regexp
7+
// Escape characters with special meaning either inside or outside character sets.
8+
// Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
9+
return str.replace(/[|\\{}()[\]^$+?*.]/g, '\\$&').replace(/-/g, '\\x2d');
710
}
811

912

@@ -78,13 +81,10 @@ module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil
7881

7982
var term = rowSearcher.getTerm(filter);
8083

81-
if (/\*/.test(term)) {
82-
var regexpFlags = '';
83-
if (!filter.flags || !filter.flags.caseSensitive) {
84-
regexpFlags += 'i';
85-
}
86-
87-
var reText = term.replace(/(\\)?\*/g, function ($0, $1) { return $1 ? $0 : '[\\s\\S]*?'; });
84+
if (/\*/.test(term)) {//this would check only start and end -> /^\*|\*$/
85+
var regexpFlags = (!filter.flags || !filter.flags.caseSensitive) ? 'i' : '';
86+
term = escapeRegExp(term);
87+
var reText = term.replace(/\\\*/g, '.*');//this would check only start and end -> /^\\\*|\\\*$/g
8888
return new RegExp('^' + reText + '$', regexpFlags);
8989
}
9090
// Otherwise default to default condition

0 commit comments

Comments
 (0)