Skip to content

Commit 9e273f6

Browse files
authored
Merge pull request #145 from racpast/fix/idna-underscore
fix: use lax IDNA profile to support underscores in domains
2 parents 4b54702 + 01e44c9 commit 9e273f6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

main.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,19 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
328328
// Skip if already an in-addr.arpa or ip6.arpa name
329329
lowerName := strings.ToLower(opts.Name)
330330
if !strings.HasSuffix(lowerName, ".in-addr.arpa") && !strings.HasSuffix(lowerName, ".ip6.arpa") {
331-
// Allow underscores during IDNA conversion
332-
_asciiName := strings.ReplaceAll(opts.Name, "_", "..")
333-
asciiName, err := idna.Lookup.ToASCII(_asciiName)
331+
// Use a custom IDNA profile to allow underscores (non-LDH characters).
332+
// Standard IDNA Lookup enforces STD3 rules which forbid underscores,
333+
// but they are valid in DNS records (e.g. TXT, SRV).
334+
p := idna.New(
335+
idna.MapForLookup(),
336+
idna.StrictDomainName(false),
337+
)
338+
339+
asciiName, err := p.ToASCII(opts.Name)
334340
if err != nil {
335341
return fmt.Errorf("idna toascii: %s", err)
336342
}
337-
opts.Name = strings.ReplaceAll(asciiName, "..", "_")
343+
opts.Name = asciiName
338344
}
339345
}
340346

0 commit comments

Comments
 (0)