[fieldWildcard] properly escape regexp control chars

This commit is contained in:
spalger 2016-04-05 02:13:21 -07:00 committed by Stéphane Campinas
parent 08f8fd7e0d
commit 385a0620c0
2 changed files with 6 additions and 2 deletions

View file

@ -10,6 +10,10 @@ describe('fieldWildcard', function () {
expect('1234a').to.match(makeRegEx('1234*'));
expect('12a34').to.match(makeRegEx('12a34'));
});
it('properly escapes regexp control characters', function () {
expect('account[user_id]').to.match(makeRegEx('account[*]'));
});
});
describe('filter', function () {

View file

@ -1,7 +1,7 @@
import { memoize } from 'lodash';
import { escapeRegExp, memoize } from 'lodash';
export const makeRegEx = memoize(function makeRegEx(glob) {
return new RegExp(glob.replace(/\*/g, '.*'));
return new RegExp(glob.split('*').map(escapeRegExp).join('.*'));
});
export function fieldWildcardMatcher(globs) {