Skip to content

Commit

Permalink
parse userinfo with multiple @
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwutingfeng committed Jun 2, 2022
1 parent e273d61 commit 61b06f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions fasttld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ var noSchemeTests = []extractTest{
{urlParams: URLParams{URL: "255.255.example.com"}, expected: &ExtractResult{SubDomain: "255.255", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "Numeric SubDomain + Domain | No Scheme"},
{urlParams: URLParams{URL: "server.example.com/path"}, expected: &ExtractResult{SubDomain: "server", Domain: "example", Suffix: "com", RegisteredDomain: "example.com", Path: "/path"}, description: "SubDomain, Domain and Path | No Scheme"},
}
var userInfoTests = []extractTest{
{urlParams: URLParams{URL: "https://[email protected]"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: "username", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "username"},
{urlParams: URLParams{URL: "https://[email protected]"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: "password", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "username + password"},
{urlParams: URLParams{URL: "https://:[email protected]"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: ":password", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "colon but empty username"},
{urlParams: URLParams{URL: "https://username:@example.com"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: "username:", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "colon but empty password"},
{urlParams: URLParams{URL: "https://usern@me:[email protected]"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: "usern@me:password", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "@ in username"},
{urlParams: URLParams{URL: "https://usern@me:p@[email protected]"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: "usern@me:p@ssword", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "@ in password"},
{urlParams: URLParams{URL: "https://usern@me:@example.com"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: "usern@me:", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "colon but empty password; @ in username"},
{urlParams: URLParams{URL: "https://:p@[email protected]"}, expected: &ExtractResult{Scheme: "https://",
UserInfo: ":p@ssword", Domain: "example", Suffix: "com", RegisteredDomain: "example.com"}, description: "colon but empty username; @ in password"},
}
var ipv4Tests = []extractTest{
{urlParams: URLParams{URL: "127.0.0.1"},
expected: &ExtractResult{Domain: "127.0.0.1",
Expand Down Expand Up @@ -586,6 +604,7 @@ func TestExtract(t *testing.T) {
for _, testCollection := range []([]extractTest){
schemeTests,
noSchemeTests,
userInfoTests,
ipv4Tests,
ipv6Tests,
ignoreSubDomainsTests,
Expand Down
2 changes: 1 addition & 1 deletion strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ func indexLastByteBefore(s string, b byte, notAfterCharsSet asciiSet) int {
if firstNotAfterCharIdx := indexAnyASCII(s, notAfterCharsSet); firstNotAfterCharIdx != -1 {
return strings.LastIndexByte(s[0:firstNotAfterCharIdx], b)
}
return strings.IndexByte(s, b)
return strings.LastIndexByte(s, b)
}

0 comments on commit 61b06f4

Please sign in to comment.