mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
When cleaning up the only element, make a nop.
We can't remove the only Sub from regexp, since the contract for some operations says that there's at least one Sub, like OpStar or OpPlus. In order to convert a single-sub element into a no-op, we change the operation to OpEmptyString. Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
This commit is contained in:
parent
8120398f6c
commit
c8bce5d8c5
|
@ -86,6 +86,16 @@ func TestMatcher(t *testing.T) {
|
||||||
value: "foo-bar",
|
value: "foo-bar",
|
||||||
match: false,
|
match: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
matcher: mustNewMatcher(t, MatchRegexp, "bar^+"),
|
||||||
|
value: "foo-bar",
|
||||||
|
match: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matcher: mustNewMatcher(t, MatchRegexp, "$+bar"),
|
||||||
|
value: "foo-bar",
|
||||||
|
match: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
|
@ -163,6 +163,9 @@ func clearBeginEndText(re *syntax.Regexp) {
|
||||||
}
|
}
|
||||||
if len(re.Sub) == 1 {
|
if len(re.Sub) == 1 {
|
||||||
if re.Sub[0].Op == syntax.OpBeginText || re.Sub[0].Op == syntax.OpEndText {
|
if re.Sub[0].Op == syntax.OpBeginText || re.Sub[0].Op == syntax.OpEndText {
|
||||||
|
// We need to remove this element. Since it's the only one, we convert into a matcher of an empty string.
|
||||||
|
// OpEmptyMatch is regexp's nop operator.
|
||||||
|
re.Op = syntax.OpEmptyMatch
|
||||||
re.Sub = nil
|
re.Sub = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue