diff --git a/model/labels/regexp.go b/model/labels/regexp.go index b2e13abca8..7868967d98 100644 --- a/model/labels/regexp.go +++ b/model/labels/regexp.go @@ -533,7 +533,7 @@ func stringMatcherFromRegexpInternal(re *syntax.Regexp) StringMatcher { // we can optimize. switch { // Literal as prefix. - case len(re.Sub) == 2 && re.Sub[0].Op == syntax.OpLiteral: + case right == nil && len(re.Sub) == 2 && re.Sub[0].Op == syntax.OpLiteral: right = stringMatcherFromRegexpInternal(re.Sub[1]) if right != nil { matches = []string{string(re.Sub[0].Rune)} @@ -541,7 +541,7 @@ func stringMatcherFromRegexpInternal(re *syntax.Regexp) StringMatcher { } // Literal as suffix. - case len(re.Sub) == 2 && re.Sub[1].Op == syntax.OpLiteral: + case left == nil && len(re.Sub) == 2 && re.Sub[1].Op == syntax.OpLiteral: left = stringMatcherFromRegexpInternal(re.Sub[0]) if left != nil { matches = []string{string(re.Sub[1].Rune)} diff --git a/model/labels/regexp_test.go b/model/labels/regexp_test.go index 3396b9da79..00538aca48 100644 --- a/model/labels/regexp_test.go +++ b/model/labels/regexp_test.go @@ -413,6 +413,11 @@ func TestStringMatcherFromRegexp(t *testing.T) { // Case insensitive alternate with same literal prefix and .* suffix. {"(?i:(xyz-016a-ixb-dp.*|xyz-016a-ixb-op.*))", &literalPrefixStringMatcher{prefix: "XYZ-016A-IXB-", prefixCaseSensitive: false, right: orStringMatcher{&literalPrefixStringMatcher{prefix: "DP", prefixCaseSensitive: false, right: anyStringWithoutNewlineMatcher{}}, &literalPrefixStringMatcher{prefix: "OP", prefixCaseSensitive: false, right: anyStringWithoutNewlineMatcher{}}}}}, {"(?i)(xyz-016a-ixb-dp.*|xyz-016a-ixb-op.*)", &literalPrefixStringMatcher{prefix: "XYZ-016A-IXB-", prefixCaseSensitive: false, right: orStringMatcher{&literalPrefixStringMatcher{prefix: "DP", prefixCaseSensitive: false, right: anyStringWithoutNewlineMatcher{}}, &literalPrefixStringMatcher{prefix: "OP", prefixCaseSensitive: false, right: anyStringWithoutNewlineMatcher{}}}}}, + // Concatenated variable length selectors are not supported. + {"foo.*.*", nil}, + {"foo.+.+", nil}, + {".*.*foo", nil}, + {".+.+foo", nil}, } { c := c t.Run(c.pattern, func(t *testing.T) {