From 58886bb85073b37e5f73d9ec5c61460166208de7 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 1 Jun 2023 14:21:22 +0100 Subject: [PATCH] [v10.0.x] Alerting: Fix matching labels with spaces in their values (#69340) Alerting: Fix matching labels with spaces in their values (#68909) Fix matching labels with spaces in their values (cherry picked from commit fb7993d0216e6677bd187d67d00d2d69f7384167) Co-authored-by: Virginia Cepeda --- .../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 2fd657a6a1b..c830d17a1f5 100644 --- a/public/app/features/alerting/unified/utils/alertmanager.test.ts +++ b/public/app/features/alerting/unified/utils/alertmanager.test.ts @@ -90,6 +90,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 96a12752b91..5a38ba275d8 100644 --- a/public/app/features/alerting/unified/utils/alertmanager.ts +++ b/public/app/features/alerting/unified/utils/alertmanager.ts @@ -167,7 +167,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) => {