Skip to content

Commit

Permalink
We removed the content before the symbol '@' in the url
Browse files Browse the repository at this point in the history
  • Loading branch information
gotoxu committed Aug 14, 2018
1 parent 27cb368 commit 3ef4cd4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
9 changes: 8 additions & 1 deletion domainutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package domainutil

import (
"strings"

"golang.org/x/net/idna"
)

Expand Down Expand Up @@ -83,13 +84,19 @@ func stripURLParts(url string) string {
url = url[index+3:]
}

// Now, if the url looks like this: username:[email protected]/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
Expand Down
29 changes: 16 additions & 13 deletions domainutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]": "google.com",
"admin:[email protected]": "gama.google.com",
"https://admin:[email protected]/path?key=value": "gama.google.com",
}

//Test each domain, some should fail (expected)
Expand Down

0 comments on commit 3ef4cd4

Please sign in to comment.