Skip to content

Commit c9bcea5

Browse files
authored
ui: Handle Query.parse inputs without a profile-type prefix (#6346)
Bare matcher inputs like `{namespace=~"a", pod=~".*"}` match the `_ matchers _` grammar rule, which returns `profileName: {}`. Both Query.fromAst and the partial-parse fallback then crashed when constructing the ProfileType from the missing value. Default to an empty ProfileType in both paths.
1 parent 9821129 commit c9bcea5

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

ui/packages/shared/parser/src/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ test('Partial Parsing ProfileName and rest', () => {
104104
});
105105
});
106106

107+
test('QueryParseBareMatchers', () => {
108+
const input = '{namespace=~"environment-afc16806", pod=~".*"}';
109+
expect(() => Query.parse(input)).not.toThrow();
110+
const q = Query.parse(input);
111+
expect(q.profileName()).toBe('');
112+
expect(q.matchersString()).toBe('namespace=~"environment-afc16806", pod=~".*"');
113+
});
114+
107115
test('Parse Multiline query', () => {
108116
expect(
109117
Query.parse(`memory:alloc_objects:count:space:bytes:delta{

ui/packages/shared/parser/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ export class Query {
185185
(e: any) =>
186186
new Matcher(e.key.value, matcherTypeFromString(e.matcherType.value), e.value.value)
187187
);
188-
return new Query(ProfileType.fromString(ast.profileName.value), matchers, '');
188+
const profileType =
189+
ast.profileName?.value !== undefined
190+
? ProfileType.fromString(ast.profileName.value)
191+
: new ProfileType('', '', '', '', '', false);
192+
return new Query(profileType, matchers, '');
189193
}
190194

191195
static parse(input: string): Query {
@@ -219,7 +223,7 @@ export class Query {
219223
(s: any) =>
220224
s.data !== undefined && Object.prototype.hasOwnProperty.call(s.data, 'profileName')
221225
).data;
222-
const rest = input.slice(column.lexerState.col - 2);
226+
const rest = column.lexerState !== undefined ? input.slice(column.lexerState.col - 2) : input;
223227
return new Query(
224228
ProfileType.fromString(data.profileName),
225229
[],

0 commit comments

Comments
 (0)