Explore: Fix logging query parser for regex with quantifiers

- ensure that selectors have to be preceded by whitespace or line beginning
- glacing over the fact that ` {0,1}` could be a valid regexp, but we're using space as query/regexp separators anyway, so I think it's fine for now
This commit is contained in:
David Kaltschmidt 2018-11-30 15:49:54 +01:00
parent 088c2e70d8
commit 11a53763e2
2 changed files with 13 additions and 2 deletions

View File

@ -42,4 +42,15 @@ describe('parseQuery', () => {
regexp: '',
});
});
it('returns query and regexp with quantifiers', () => {
expect(parseQuery('{foo="bar"} \\.java:[0-9]{1,5}')).toEqual({
query: '{foo="bar"}',
regexp: '\\.java:[0-9]{1,5}',
});
expect(parseQuery('\\.java:[0-9]{1,5} {foo="bar"}')).toEqual({
query: '{foo="bar"}',
regexp: '\\.java:[0-9]{1,5}',
});
});
});

View File

@ -1,11 +1,11 @@
const selectorRegexp = /{[^{]*}/g;
const selectorRegexp = /(?:^|\s){[^{]*}/g;
export function parseQuery(input: string) {
const match = input.match(selectorRegexp);
let query = '';
let regexp = input;
if (match) {
query = match[0];
query = match[0].trim();
regexp = input.replace(selectorRegexp, '').trim();
}