From a3c8fd3e9ba21b1b046bdcf4e1eab015356c0740 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 1 Jun 2023 13:55:34 +0100 Subject: [PATCH] [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 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 836efd206e9..d21483d9fbe 100644 --- a/public/app/features/alerting/unified/utils/alertmanager.ts +++ b/public/app/features/alerting/unified/utils/alertmanager.ts @@ -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) => {