From 05f073f42f8e93f93c456d30bef266c1d12cdffa Mon Sep 17 00:00:00 2001 From: gotjosh Date: Tue, 28 Jun 2022 11:51:06 +0100 Subject: [PATCH] Ensure matcher values are present when parsing matchers from strings Fixes #2936 Signed-off-by: gotjosh --- pkg/labels/parse.go | 6 +++++- pkg/labels/parse_test.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/labels/parse.go b/pkg/labels/parse.go index 0a242d50..d0978ff6 100644 --- a/pkg/labels/parse.go +++ b/pkg/labels/parse.go @@ -120,8 +120,12 @@ func ParseMatcher(s string) (_ *Matcher, err error) { return nil, errors.Errorf("bad matcher format: %s", s) } + rawValue := ms[3] + if len(rawValue) == 0 { + return nil, errors.Errorf("matcher value is not present: %s", s) + } + var ( - rawValue = ms[3] value strings.Builder escaped bool expectTrailingQuote bool diff --git a/pkg/labels/parse_test.go b/pkg/labels/parse_test.go index c15541b8..b1f53ef2 100644 --- a/pkg/labels/parse_test.go +++ b/pkg/labels/parse_test.go @@ -189,6 +189,10 @@ func TestMatchers(t *testing.T) { return append(ms, m, m2) }(), }, + { + input: `job=`, + err: `matcher value is not present: job=`, + }, { input: `job="value`, err: `matcher value contains unescaped double quote: "value`,