Skip to content

Commit 6382808

Browse files
authored
fix: adjust label validation for max length of 63 characters (#273)
According to the api documentation, the length of a label value must be a string of 63 characters or fewer. The currently used regex for the validation allows 64 char long values. Signed-off-by: Florian Bauer <[email protected]>
1 parent 7918f21 commit 6382808

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

hcloud/labels.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
)
77

88
var keyRegexp = regexp.MustCompile(
9-
`^([a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]){0,253}[a-z0-9A-Z])?/)?[a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]|){0,62}[a-z0-9A-Z])?$`)
10-
var valueRegexp = regexp.MustCompile(`^(([a-z0-9A-Z](?:[\-_.]|[a-z0-9A-Z]){0,62})?[a-z0-9A-Z]$|$)`)
9+
`^([a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]){0,253}[a-z0-9A-Z])?/)?[a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]|){0,61}[a-z0-9A-Z])?$`)
10+
var valueRegexp = regexp.MustCompile(`^(([a-z0-9A-Z](?:[\-_.]|[a-z0-9A-Z]){0,61})?[a-z0-9A-Z]$|$)`)
1111

1212
func ValidateResourceLabels(labels map[string]interface{}) (bool, error) {
1313
for k, v := range labels {

hcloud/labels_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestCheckLabels(t *testing.T) {
2929
"incorrect.com-",
3030
"incorr,ect.com-",
3131
"incorrect-111111111111111111111111111111111111111111111111111111111111.com",
32+
"63-characters-are-allowed-in-a-label__this-is-one-character-more",
3233
}
3334

3435
for _, label := range incorrectLabels {

0 commit comments

Comments
 (0)