Add punycode support

Fixes #8
This commit is contained in:
Filippo Valsorda
2018-06-28 01:44:13 -04:00
parent e4c5c312a7
commit 75a36a6de4
98 changed files with 137783 additions and 3 deletions

11
main.go
View File

@@ -15,6 +15,8 @@ import (
"path/filepath"
"regexp"
"runtime"
"golang.org/x/net/idna"
)
func main() {
@@ -102,11 +104,16 @@ Change the CA certificate and key storage location by setting $CAROOT.
}
hostnameRegexp := regexp.MustCompile(`(?i)^(\*\.)?[0-9a-z_-]([0-9a-z._-]*[0-9a-z_-])?$`)
for _, name := range args {
for i, name := range args {
if ip := net.ParseIP(name); ip != nil {
continue
}
if hostnameRegexp.MatchString(name) {
punycode, err := idna.ToASCII(name)
if err != nil {
log.Fatalf("ERROR: %q is not a valid hostname or IP: %s", name, err)
}
args[i] = punycode
if hostnameRegexp.MatchString(punycode) {
continue
}
log.Fatalf("ERROR: %q is not a valid hostname or IP", name)