Skip to content

Commit

Permalink
route53: Don't escape '*' as leftmost label of a domain name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Jan 10, 2025
1 parent 41fcc0f commit 09ca52f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 15 additions & 1 deletion internal/service/route53/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ func normalizeDomainNameToAPI(input string) string {
output.WriteRune(unicode.ToLower(ch))
case ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch == '-' || ch == '.' || ch == '_':
output.WriteRune(ch)
case ch == '*':
// * as leftmost label is retained.
const (
lenDelimiter = 1
)
if output.Len() == 0 {
if bytes, err := br.Peek(lenDelimiter); err == nil && bytes[0] == '.' {
output.WriteRune(ch)
continue
}
}
// Three-digit octal code.
output.WriteString(fmt.Sprintf("\\%03o", ch))
case ch == '\\':
const (
lenOctalCode = 3
Expand All @@ -52,7 +65,8 @@ func normalizeDomainNameToAPI(input string) string {
_, _ = br.Discard(lenOctalCode)
continue
}
fallthrough
// Three-digit octal code.
output.WriteString(fmt.Sprintf("\\%03o", ch))
default:
// Three-digit octal code.
output.WriteString(fmt.Sprintf("\\%03o", ch))
Expand Down
5 changes: 4 additions & 1 deletion internal/service/route53/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func TestNormalizeNameIntoAPIRepresentation(t *testing.T) {
{"AbC.example.com", "abc.example.com"},

// convert into escape code
{"*.example.com", "\\052.example.com"},
{"*.example.com", "*.example.com"}, // * as leftmost label is retained
{"*bc.example.com", "\\052bc.example.com"},
{"a*c.example.com", "a\\052c.example.com"},
{"ab*.example.com", "ab\\052.example.com"},
{"!.example.com", "\\041.example.com"},
{"a/b.example.com", "a\\057b.example.com"},
{"/.example.com", "\\057.example.com"},
Expand Down

0 comments on commit 09ca52f

Please sign in to comment.