diff --git a/main.go b/main.go index b3742b9..574d04e 100644 --- a/main.go +++ b/main.go @@ -326,11 +326,13 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation // Skip if already an in-addr.arpa or ip6.arpa name lowerName := strings.ToLower(opts.Name) if !strings.HasSuffix(lowerName, ".in-addr.arpa") && !strings.HasSuffix(lowerName, ".ip6.arpa") { - asciiName, err := idna.Lookup.ToASCII(opts.Name) + // Allow underscores during IDNA conversion + _asciiName := strings.ReplaceAll(opts.Name, "_", "..") + asciiName, err := idna.Lookup.ToASCII(_asciiName) if err != nil { return fmt.Errorf("idna toascii: %s", err) } - opts.Name = asciiName + opts.Name = strings.ReplaceAll(asciiName, "..", "_") } } diff --git a/main_test.go b/main_test.go index 2032634..0dc04b1 100644 --- a/main_test.go +++ b/main_test.go @@ -612,3 +612,16 @@ func TestMainTypeNotation(t *testing.T) { assert.Nil(t, err) assert.Regexp(t, regexp.MustCompile(`cloudflare.com. .* HTTPS .*`), outType65.String()) } + +func TestIDNAUnderscoreASCII(t *testing.T) { + // Ensure ASCII names with underscores are not mangled by IDNA processing + out, err := run( + "--all", + "-q", "_acme-challenge.example.com", + "-t", "TXT", + ) + assert.Nil(t, err) + // Expect the question or answer to include the literal underscore name + re := regexp.MustCompile(regexp.QuoteMeta("_acme-challenge.example.com.")) + assert.Regexp(t, re, out.String()) +}