File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import (
1717 "github.com/jessevdk/go-flags"
1818 "github.com/miekg/dns"
1919 log "github.com/sirupsen/logrus"
20+ "golang.org/x/net/idna"
2021
2122 "github.com/natesales/q/cli"
2223 "github.com/natesales/q/output"
@@ -320,6 +321,19 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
320321 rrTypes [dns .StringToType ["PTR" ]] = true
321322 }
322323
324+ // IDNA (punycode) normalize non-ASCII domain names unless reverse lookup
325+ if opts .Name != "" && ! opts .Reverse {
326+ // Skip if already an in-addr.arpa or ip6.arpa name
327+ lowerName := strings .ToLower (opts .Name )
328+ if ! strings .HasSuffix (lowerName , ".in-addr.arpa" ) && ! strings .HasSuffix (lowerName , ".ip6.arpa" ) {
329+ asciiName , err := idna .Lookup .ToASCII (opts .Name )
330+ if err != nil {
331+ return fmt .Errorf ("idna toascii: %s" , err )
332+ }
333+ opts .Name = asciiName
334+ }
335+ }
336+
323337 // Log RR types
324338 if opts .Verbose {
325339 log .Debugf ("Name: %s" , opts .Name )
Original file line number Diff line number Diff line change 99 "testing"
1010
1111 "github.com/stretchr/testify/assert"
12+ "golang.org/x/net/idna"
1213
1314 "github.com/natesales/q/cli"
1415 "github.com/natesales/q/transport"
@@ -72,6 +73,19 @@ func TestMainJSONFormat(t *testing.T) {
7273 assert .Contains (t , o , `"txt":["v=spf1 -all"` )
7374}
7475
76+ func TestMainIDNAQuery (t * testing.T ) {
77+ out , err := run (
78+ "--all" ,
79+ "-q" , "www.饭太硬.com" ,
80+ "-t" , "A" ,
81+ )
82+ assert .Nil (t , err )
83+ ascii , err := idna .Lookup .ToASCII ("www.饭太硬.com" )
84+ assert .Nil (t , err )
85+ re := regexp .MustCompile (regexp .QuoteMeta (ascii + "." ))
86+ assert .Regexp (t , re , out .String ())
87+ }
88+
7589func TestMainInvalidOutputFormat (t * testing.T ) {
7690 _ , err := run (
7791 "--all" ,
You can’t perform that action at this time.
0 commit comments