From fb7993d0216e6677bd187d67d00d2d69f7384167 Mon Sep 17 00:00:00 2001 From: Virginia Cepeda Date: Wed, 31 May 2023 17:10:00 -0300 Subject: [PATCH] Alerting: Fix matching labels with spaces in their values (#68909) Fix matching labels with spaces in their values --- .../alerting/unified/utils/alertmanager.test.ts | 11 +++++++++++ .../features/alerting/unified/utils/alertmanager.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/public/app/features/alerting/unified/utils/alertmanager.test.ts b/public/app/features/alerting/unified/utils/alertmanager.test.ts index 30954e9b35c..51b09740332 100644 --- a/public/app/features/alerting/unified/utils/alertmanager.test.ts +++ b/public/app/features/alerting/unified/utils/alertmanager.test.ts @@ -85,6 +85,17 @@ describe('Alertmanager utils', () => { ]); }); + it('should parse with spaces in the value', () => { + expect(parseMatchers('foo=bar bazz')).toEqual([ + { + name: 'foo', + value: 'bar bazz', + isRegex: false, + isEqual: true, + }, + ]); + }); + it('should return nothing for invalid operator', () => { expect(parseMatchers('foo=!bar')).toEqual([]); }); diff --git a/public/app/features/alerting/unified/utils/alertmanager.ts b/public/app/features/alerting/unified/utils/alertmanager.ts index a3992f04551..02488b99ad0 100644 --- a/public/app/features/alerting/unified/utils/alertmanager.ts +++ b/public/app/features/alerting/unified/utils/alertmanager.ts @@ -132,7 +132,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) => {