Skip to content

Commit

Permalink
fix unhandled edge case for some urls of format domain+singleTLD
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwutingfeng committed Apr 30, 2022
1 parent 4399c5a commit 04e6a80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fasttld.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func (f *FastTLD) Extract(e URLParams) *ExtractResult {
break
}
} else {
if previousSepIdx != len(netloc) {
sepIdx = previousSepIdx
}
break
}
}
Expand Down
5 changes: 5 additions & 0 deletions fasttld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ var tldExtractGoTests = []extractTest{
{urlParams: URLParams{URL: "http://domainer.xn--ciqpn.hk"}, expected: &ExtractResult{Scheme: "http://", Domain: "domainer", Suffix: "xn--ciqpn.hk", RegisteredDomain: "domainer.xn--ciqpn.hk"}, description: "Basic URL with mixed punycode international TLD (result in unicode)"},
{urlParams: URLParams{URL: "http://domainer.xn--55qx5d.xn--j6w193g"}, expected: &ExtractResult{Scheme: "http://", Domain: "domainer", Suffix: "xn--55qx5d.xn--j6w193g", RegisteredDomain: "domainer.xn--55qx5d.xn--j6w193g"}, description: "Basic URL with full punycode international TLD (result in unicode)"},

{urlParams: URLParams{URL: "https://example.ai/en"}, expected: &ExtractResult{Scheme: "https://", Domain: "example", Suffix: "ai", RegisteredDomain: "example.ai", Path: "en"}, description: "Domain only + ai"},
{urlParams: URLParams{URL: "https://example.co/en"}, expected: &ExtractResult{Scheme: "https://", Domain: "example", Suffix: "co", RegisteredDomain: "example.co", Path: "en"}, description: "Domain only + co"},
{urlParams: URLParams{URL: "https://example.sg/en"}, expected: &ExtractResult{Scheme: "https://", Domain: "example", Suffix: "sg", RegisteredDomain: "example.sg", Path: "en"}, description: "Domain only + sg"},
{urlParams: URLParams{URL: "https://example.tv/en"}, expected: &ExtractResult{Scheme: "https://", Domain: "example", Suffix: "tv", RegisteredDomain: "example.tv", Path: "en"}, description: "Domain only + tv"},

// {urlParams: URLParams{URL: "git+ssh://www.!github.com/"}, expected: &ExtractResult{}, description: "Full git+ssh URL with bad domain"},
}

Expand Down

0 comments on commit 04e6a80

Please sign in to comment.