Skip to content

Commit

Permalink
fix: adjust label validation for max length of 63 characters (#273)
Browse files Browse the repository at this point in the history
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 <florian@fsrv.xyz>
  • Loading branch information
fsrv-xyz committed Jun 16, 2023
1 parent 7918f21 commit 6382808
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hcloud/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

var keyRegexp = regexp.MustCompile(
`^([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])?$`)
var valueRegexp = regexp.MustCompile(`^(([a-z0-9A-Z](?:[\-_.]|[a-z0-9A-Z]){0,62})?[a-z0-9A-Z]$|$)`)
`^([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])?$`)
var valueRegexp = regexp.MustCompile(`^(([a-z0-9A-Z](?:[\-_.]|[a-z0-9A-Z]){0,61})?[a-z0-9A-Z]$|$)`)

func ValidateResourceLabels(labels map[string]interface{}) (bool, error) {
for k, v := range labels {
Expand Down
1 change: 1 addition & 0 deletions hcloud/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestCheckLabels(t *testing.T) {
"incorrect.com-",
"incorr,ect.com-",
"incorrect-111111111111111111111111111111111111111111111111111111111111.com",
"63-characters-are-allowed-in-a-label__this-is-one-character-more",
}

for _, label := range incorrectLabels {
Expand Down

0 comments on commit 6382808

Please sign in to comment.