Fix Matcher.String() with empty label name

When the label name is empty, which can happen now with quoted label
name, it should be quoted when printed as a string again.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
pull/14296/head
Oleg Zaytsev 1 year ago
parent 5a218708f1
commit 03cf6141d4
No known key found for this signature in database
GPG Key ID: 7E9FE9FD48F512EF
  1. 2
      model/labels/matcher.go
  2. 7
      promql/parser/printer_test.go

@ -101,7 +101,7 @@ func (m *Matcher) shouldQuoteName() bool {
}
return true
}
return false
return len(m.Name) == 0
}
// Matches returns whether the matcher matches the given string value.

@ -148,6 +148,13 @@ func TestExprString(t *testing.T) {
in: `{"_0"="1"}`,
out: `{_0="1"}`,
},
{
in: `{""="0"}`,
},
{
in: "{``=\"0\"}",
out: `{""="0"}`,
},
}
for _, test := range inputs {

Loading…
Cancel
Save