Merge pull request #3671 from grobinson-grafana/grobinson/fix-missing-check-valid-labels
Fix missing check for len(name) == 0
This commit is contained in:
commit
30fa9cd44b
|
@ -244,6 +244,9 @@ func isValidClassicLabelName(_ log.Logger) func(model.LabelName) bool {
|
||||||
// isValidUTF8LabelName returns true if the string is a valid UTF-8 label name.
|
// isValidUTF8LabelName returns true if the string is a valid UTF-8 label name.
|
||||||
func isValidUTF8LabelName(_ log.Logger) func(model.LabelName) bool {
|
func isValidUTF8LabelName(_ log.Logger) func(model.LabelName) bool {
|
||||||
return func(name model.LabelName) bool {
|
return func(name model.LabelName) bool {
|
||||||
|
if len(name) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return utf8.ValidString(string(name))
|
return utf8.ValidString(string(name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,19 +172,23 @@ func TestIsValidClassicLabelName(t *testing.T) {
|
||||||
input model.LabelName
|
input model.LabelName
|
||||||
expected bool
|
expected bool
|
||||||
}{{
|
}{{
|
||||||
name: "is accepted",
|
name: "foo is accepted",
|
||||||
input: "foo",
|
input: "foo",
|
||||||
expected: true,
|
expected: true,
|
||||||
}, {
|
}, {
|
||||||
name: "is also accepted",
|
name: "starts with underscore and ends with number is accepted",
|
||||||
input: "_foo1",
|
input: "_foo1",
|
||||||
expected: true,
|
expected: true,
|
||||||
}, {
|
}, {
|
||||||
name: "is not accepted",
|
name: "empty is not accepted",
|
||||||
|
input: "",
|
||||||
|
expected: false,
|
||||||
|
}, {
|
||||||
|
name: "starts with number is not accepted",
|
||||||
input: "0foo",
|
input: "0foo",
|
||||||
expected: false,
|
expected: false,
|
||||||
}, {
|
}, {
|
||||||
name: "is also not accepted",
|
name: "contains emoji is not accepted",
|
||||||
input: "foo🙂",
|
input: "foo🙂",
|
||||||
expected: false,
|
expected: false,
|
||||||
}}
|
}}
|
||||||
|
@ -203,21 +207,25 @@ func TestIsValidUTF8LabelName(t *testing.T) {
|
||||||
input model.LabelName
|
input model.LabelName
|
||||||
expected bool
|
expected bool
|
||||||
}{{
|
}{{
|
||||||
name: "is accepted",
|
name: "foo is accepted",
|
||||||
input: "foo",
|
input: "foo",
|
||||||
expected: true,
|
expected: true,
|
||||||
}, {
|
}, {
|
||||||
name: "is also accepted",
|
name: "starts with underscore and ends with number is accepted",
|
||||||
input: "_foo1",
|
input: "_foo1",
|
||||||
expected: true,
|
expected: true,
|
||||||
}, {
|
}, {
|
||||||
name: "is accepted in UTF-8",
|
name: "starts with number is accepted",
|
||||||
input: "0foo",
|
input: "0foo",
|
||||||
expected: true,
|
expected: true,
|
||||||
}, {
|
}, {
|
||||||
name: "is also accepted with UTF-8",
|
name: "contains emoji is accepted",
|
||||||
input: "foo🙂",
|
input: "foo🙂",
|
||||||
expected: true,
|
expected: true,
|
||||||
|
}, {
|
||||||
|
name: "empty is not accepted",
|
||||||
|
input: "",
|
||||||
|
expected: false,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in New Issue