Skip to content

Commit 6bbf18b

Browse files
committed
Update dns.SafeZoneName to handle empty input
1 parent ba9b76d commit 6bbf18b

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/pkg/clouds/gcp/dns.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ var safeZoneRE = regexp.MustCompile(`[^a-z0-9-]+`)
101101

102102
// Zone names have the same requirements as label values.
103103
func SafeZoneName(input string) string {
104-
input = strings.ToLower(input) // Rule 1: lowercase
105-
safe := safeZoneRE.ReplaceAllString(input, "-") // Rule 1: only letters, numbers, and hyphen
106-
safe = strings.Trim(safe, "-") // Rule 3, 4: trim hyphens from start and end
107-
if len(safe) == 0 || (safe[0] < 'a' || safe[0] > 'z') { // Rule 3: must start with a letter
104+
input = strings.ToLower(input) // Rule 1: lowercase
105+
safe := safeZoneRE.ReplaceAllString(input, "-") // Rule 1: only letters, numbers, and hyphen
106+
safe = strings.Trim(safe, "-") // Rule 3, 4: trim hyphens from start and end
107+
if len(safe) == 0 {
108+
safe = "zone"
109+
}
110+
if safe[0] < 'a' || safe[0] > 'z' { // Rule 3: must start with a letter
108111
safe = "zone-" + safe
109112
}
110113
return hashTrim(safe, 63) // Rule 2: max length 63

0 commit comments

Comments
 (0)