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>
This commit is contained in:
Oleg Zaytsev 2024-06-13 18:46:35 +02:00
parent 5a218708f1
commit 03cf6141d4
No known key found for this signature in database
GPG Key ID: 7E9FE9FD48F512EF
2 changed files with 8 additions and 1 deletions

View File

@ -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.

View File

@ -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 {