Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci committed Sep 29, 2023
1 parent c28d940 commit 5ae9c19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions model/labels/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ 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)}
matchesCaseSensitive = !isCaseInsensitive(re.Sub[0])
}

// 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)}
Expand Down
5 changes: 5 additions & 0 deletions model/labels/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5ae9c19

Please sign in to comment.