Skip to content

Commit

Permalink
[hotfix/6360]
Browse files Browse the repository at this point in the history
 - updated escapeRegExp
 - now escapes term first, before changing *
 - changed to greedy
  • Loading branch information
prx-lmo authored and mportuga committed Jul 31, 2021
1 parent 63e49b1 commit 1201ad2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/core/src/js/services/rowSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
var module = angular.module('ui.grid');

function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
// based on https://github.com/sindresorhus/escape-string-regexp
// Escape characters with special meaning either inside or outside character sets.
// 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.
return str.replace(/[|\\{}()[\]^$+?*.]/g, '\\$&').replace(/-/g, '\\x2d');
}


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

var term = rowSearcher.getTerm(filter);

if (/\*/.test(term)) {
var regexpFlags = '';
if (!filter.flags || !filter.flags.caseSensitive) {
regexpFlags += 'i';
}

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

0 comments on commit 1201ad2

Please sign in to comment.