mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[fieldWildcard] properly escape regexp control chars
This commit is contained in:
parent
08f8fd7e0d
commit
385a0620c0
2 changed files with 6 additions and 2 deletions
|
@ -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 () {
|
|
@ -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) {
|
Loading…
Add table
Add a link
Reference in a new issue