diff --git a/model/labels/matcher.go b/model/labels/matcher.go index 8e220e392..a09c838e3 100644 --- a/model/labels/matcher.go +++ b/model/labels/matcher.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. diff --git a/promql/parser/printer_test.go b/promql/parser/printer_test.go index f224d841d..d2e301a88 100644 --- a/promql/parser/printer_test.go +++ b/promql/parser/printer_test.go @@ -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 {