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.
|
||||
func isValidUTF8LabelName(_ log.Logger) func(model.LabelName) bool {
|
||||
return func(name model.LabelName) bool {
|
||||
if len(name) == 0 {
|
||||
return false
|
||||
}
|
||||
return utf8.ValidString(string(name))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,19 +172,23 @@ func TestIsValidClassicLabelName(t *testing.T) {
|
|||
input model.LabelName
|
||||
expected bool
|
||||
}{{
|
||||
name: "is accepted",
|
||||
name: "foo is accepted",
|
||||
input: "foo",
|
||||
expected: true,
|
||||
}, {
|
||||
name: "is also accepted",
|
||||
name: "starts with underscore and ends with number is accepted",
|
||||
input: "_foo1",
|
||||
expected: true,
|
||||
}, {
|
||||
name: "is not accepted",
|
||||
name: "empty is not accepted",
|
||||
input: "",
|
||||
expected: false,
|
||||
}, {
|
||||
name: "starts with number is not accepted",
|
||||
input: "0foo",
|
||||
expected: false,
|
||||
}, {
|
||||
name: "is also not accepted",
|
||||
name: "contains emoji is not accepted",
|
||||
input: "foo🙂",
|
||||
expected: false,
|
||||
}}
|
||||
|
@ -203,21 +207,25 @@ func TestIsValidUTF8LabelName(t *testing.T) {
|
|||
input model.LabelName
|
||||
expected bool
|
||||
}{{
|
||||
name: "is accepted",
|
||||
name: "foo is accepted",
|
||||
input: "foo",
|
||||
expected: true,
|
||||
}, {
|
||||
name: "is also accepted",
|
||||
name: "starts with underscore and ends with number is accepted",
|
||||
input: "_foo1",
|
||||
expected: true,
|
||||
}, {
|
||||
name: "is accepted in UTF-8",
|
||||
name: "starts with number is accepted",
|
||||
input: "0foo",
|
||||
expected: true,
|
||||
}, {
|
||||
name: "is also accepted with UTF-8",
|
||||
name: "contains emoji is accepted",
|
||||
input: "foo🙂",
|
||||
expected: true,
|
||||
}, {
|
||||
name: "empty is not accepted",
|
||||
input: "",
|
||||
expected: false,
|
||||
}}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue