-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We removed the content before the symbol '@' in the url
- Loading branch information
Showing
2 changed files
with
24 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:[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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|