Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/validators/domain_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ func (v *DomainValidator) getHostname(hostname string) (string, error) {
if net.ParseIP(hostname) != nil {
return "", fmt.Errorf("ip addresses are not supported")
}
hostname, err := idna.Lookup.ToASCII(hostname)
i := idna.New(
idna.MapForLookup(),
idna.Transitional(false),
idna.BidiRule(),
idna.StrictDomainName(false),
idna.CheckHyphens(false),
idna.CheckJoiners(false),
)
hostname, err := i.ToASCII(hostname)
if err != nil {
return "", fmt.Errorf("failed to convert hostname to ascii: %w", err)
}
Expand Down
16 changes: 13 additions & 3 deletions pkg/validators/domain_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func TestDomainValidator_SafeHostname(t *testing.T) {
input: "https://example.com",
expected: "example.com",
},
{
description: "Domain with underscores should pass",
input: "https://my_domain.com",
expected: "my_domain.com",
},
{
description: "Domain with leading hyphen should pass",
input: "https://-my-domain.com",
expected: "-my-domain.com",
},
{
description: "Domain without scheme should parse if scheme is disabled",
input: "example.com",
Expand Down Expand Up @@ -108,7 +118,7 @@ func TestDomainValidator_SafeHostname(t *testing.T) {
},
{
description: "Invalid IDNA domain should fail",
input: "ab--cd.example.com",
input: "xn--r-kva.example.com",
errorFunc: func(t *testing.T, e error) {
assert.ErrorContains(t, e, "invalid label")
},
Expand Down Expand Up @@ -196,7 +206,7 @@ func TestDomainValidator_Validate(t *testing.T) {
},
{
description: "Failure to format expected domain should fail",
expected: "ab--cd.example.com",
expected: "xn--r-kva.example.com",
actual: "example.com",
errorFunc: func(t *testing.T, e error) {
assert.ErrorContains(t, e, "idna: invalid label")
Expand All @@ -205,7 +215,7 @@ func TestDomainValidator_Validate(t *testing.T) {
{
description: "Failure to format check domain should fail",
expected: "example.com",
actual: "ab--cd.example.com",
actual: "xn--r-kva.example.com",
errorFunc: func(t *testing.T, e error) {
assert.ErrorContains(t, e, "idna: invalid label")
},
Expand Down
Loading