Skip to content

Commit

Permalink
[fieldWildcard] properly bind the regexp to the ends
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger authored and scampi committed Jun 2, 2016
1 parent da62b2a commit e89ceea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/ui/public/field_wildcard/__tests__/field_wildcard.js
Expand Up @@ -14,6 +14,15 @@ describe('fieldWildcard', function () {
it('properly escapes regexp control characters', function () {
expect('account[user_id]').to.match(makeRegEx('account[*]'));
});

it('properly limits matches without wildcards', function () {
expect('username').to.match(makeRegEx('*name'));
expect('username').to.match(makeRegEx('user*'));
expect('username').to.match(makeRegEx('username'));
expect('username').to.not.match(makeRegEx('user'));
expect('username').to.not.match(makeRegEx('name'));
expect('username').to.not.match(makeRegEx('erna'));
});
});

describe('filter', function () {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/field_wildcard/field_wildcard.js
@@ -1,7 +1,7 @@
import { escapeRegExp, memoize } from 'lodash';

export const makeRegEx = memoize(function makeRegEx(glob) {
return new RegExp(glob.split('*').map(escapeRegExp).join('.*'));
return new RegExp('^' + glob.split('*').map(escapeRegExp).join('.*') + '$');
});

export function fieldWildcardMatcher(globs) {
Expand Down

0 comments on commit e89ceea

Please sign in to comment.