Alerting: Fix matching labels with spaces in their values (#68909)

Fix matching labels with spaces in their values
This commit is contained in:
Virginia Cepeda 2023-05-31 17:10:00 -03:00 committed by GitHub
parent 0c85327bed
commit fb7993d021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -85,6 +85,17 @@ describe('Alertmanager utils', () => {
]); ]);
}); });
it('should parse with spaces in the value', () => {
expect(parseMatchers('foo=bar bazz')).toEqual<Matcher[]>([
{
name: 'foo',
value: 'bar bazz',
isRegex: false,
isEqual: true,
},
]);
});
it('should return nothing for invalid operator', () => { it('should return nothing for invalid operator', () => {
expect(parseMatchers('foo=!bar')).toEqual([]); expect(parseMatchers('foo=!bar')).toEqual([]);
}); });

View File

@ -132,7 +132,7 @@ export function matcherToObjectMatcher(matcher: Matcher): ObjectMatcher {
} }
export function parseMatchers(matcherQueryString: string): Matcher[] { export function parseMatchers(matcherQueryString: string): Matcher[] {
const matcherRegExp = /\b([\w.-]+)(=~|!=|!~|=(?="?\w))"?([^"\n,} ]*)"?/g; const matcherRegExp = /\b([\w.-]+)(=~|!=|!~|=(?="?\w))"?([^"\n,}]*)"?/g;
const matchers: Matcher[] = []; const matchers: Matcher[] = [];
matcherQueryString.replace(matcherRegExp, (_, key, operator, value) => { matcherQueryString.replace(matcherRegExp, (_, key, operator, value) => {