diff --git a/domainutil/util.go b/domainutil/util.go index 6c376f0..e374036 100644 --- a/domainutil/util.go +++ b/domainutil/util.go @@ -2,6 +2,7 @@ package domainutil import ( "strings" + "golang.org/x/net/idna" ) @@ -83,13 +84,19 @@ func stripURLParts(url string) string { url = url[index+3:] } + // Now, if the url looks like this: username:password@www.example.com/path?query=? + // we remove the content before the '@' symbol + if index := strings.Index(url, "@"); index > -1 { + url = url[index+1:] + } + //Strip path (and query with it) if index := strings.Index(url, "/"); index > -1 { url = url[:index] } else if index := strings.Index(url, "?"); index > -1 { //Strip query if path is not found url = url[:index] } - + //Convert domain to unicode if strings.Index(url, "xn--") != -1 { var err error diff --git a/domainutil/util_test.go b/domainutil/util_test.go index 612e2b3..97ed13f 100644 --- a/domainutil/util_test.go +++ b/domainutil/util_test.go @@ -168,19 +168,22 @@ func BenchmarkDomain(b *testing.B) { func TestStripURLParts(t *testing.T) { //Test cases cases := map[string]string{ - "http://google.com": "google.com", - "http://google.com/ding?true": "google.com", - "google.com/?ding=false": "google.com", - "google.com?ding=false": "google.com", - "nonexist.***": "nonexist.***", - "google.com": "google.com", - "google.co.uk": "google.co.uk", - "gama.google.com": "gama.google.com", - "gama.google.co.uk": "gama.google.co.uk", - "beta.gama.google.co.uk": "beta.gama.google.co.uk", - "https://beta.gama.google.co.uk": "beta.gama.google.co.uk", - "xn--n3h.example": "☃.example", - "xn--äää": "", + "http://google.com": "google.com", + "http://google.com/ding?true": "google.com", + "google.com/?ding=false": "google.com", + "google.com?ding=false": "google.com", + "nonexist.***": "nonexist.***", + "google.com": "google.com", + "google.co.uk": "google.co.uk", + "gama.google.com": "gama.google.com", + "gama.google.co.uk": "gama.google.co.uk", + "beta.gama.google.co.uk": "beta.gama.google.co.uk", + "https://beta.gama.google.co.uk": "beta.gama.google.co.uk", + "xn--n3h.example": "☃.example", + "xn--äää": "", + "http://admin:adminpw@google.com": "google.com", + "admin:adminpw@gama.google.com": "gama.google.com", + "https://admin:adminpw@gama.google.com/path?key=value": "gama.google.com", } //Test each domain, some should fail (expected)