[v9.5.x] Alerting: Fix matching labels with spaces in their values (#69339)

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

Fix matching labels with spaces in their values

(cherry picked from commit fb7993d021)

Co-authored-by: Virginia Cepeda <virginia.cepeda@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-06-01 09:55:34 -03:00
committed by GitHub
co-authored by Virginia Cepeda
parent 0f9f72d46b
commit a3c8fd3e9b
2 changed files with 12 additions and 1 deletions
@@ -90,6 +90,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', () => {
expect(parseMatchers('foo=!bar')).toEqual([]);
});
@@ -165,7 +165,7 @@ export function matcherToObjectMatcher(matcher: Matcher): ObjectMatcher {
}
export function parseMatchers(matcherQueryString: string): Matcher[] {
const matcherRegExp = /\b([\w.-]+)(=~|!=|!~|=(?="?\w))"?([^"\n,} ]*)"?/g;
const matcherRegExp = /\b([\w.-]+)(=~|!=|!~|=(?="?\w))"?([^"\n,}]*)"?/g;
const matchers: Matcher[] = [];
matcherQueryString.replace(matcherRegExp, (_, key, operator, value) => {