From 04e6a8002bf60e03abe57c94c2c8b69a5df72a70 Mon Sep 17 00:00:00 2001 From: Tingfeng Date: Sun, 1 May 2022 03:08:04 +0800 Subject: [PATCH] fix unhandled edge case for some urls of format domain+singleTLD --- fasttld.go | 3 +++ fasttld_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/fasttld.go b/fasttld.go index 864e13e..c644801 100644 --- a/fasttld.go +++ b/fasttld.go @@ -280,6 +280,9 @@ func (f *FastTLD) Extract(e URLParams) *ExtractResult { break } } else { + if previousSepIdx != len(netloc) { + sepIdx = previousSepIdx + } break } } diff --git a/fasttld_test.go b/fasttld_test.go index 7b85d5a..03e390a 100644 --- a/fasttld_test.go +++ b/fasttld_test.go @@ -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"}, }