Skip to content

Commit

Permalink
fixed tld bug
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4f53 committed Aug 6, 2024
1 parent b93e157 commit f064c83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 8 additions & 4 deletions textsubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func getSubdomains(text string) ([]string, error) {
)

if err != nil {
return subdomains, err
// TLD is not in the publicsuffix list, skip
// return subdomains, err
}

if len(domain) != 0 && item[0] != '-' {
Expand Down Expand Up @@ -125,7 +126,8 @@ func SubdomainsOnly(text string, removeDuplicates bool) ([]string, error) {
)

if err != nil {
return results, err
// TLD is not in the publicsuffix list, skip
// return results, err
}

if domain != item {
Expand Down Expand Up @@ -166,7 +168,8 @@ func DomainsOnly(text string, removeDuplicates bool) ([]string, error) {
)

if err != nil {
return results, err
// TLD is not in the publicsuffix list, skip
// return results, err
}

results = append(results, domain)
Expand Down Expand Up @@ -210,7 +213,8 @@ func SubdomainAndDomainPair(text string, removeDuplicates bool) ([]SubAndDom, er
)

if err != nil {
return results, err
// TLD is not in the publicsuffix list, skip
// return results, err
}

var pair SubAndDom
Expand Down
21 changes: 18 additions & 3 deletions textsubs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,38 @@ func TestMyFunction(t *testing.T) {
}

t.Log("Found subdomains: ")
output_subdomains := SubdomainsOnly(string(data), true)
output_subdomains, err := SubdomainsOnly(string(data), true)

if err != nil {
t.Error(err)
}

for index, item := range output_subdomains {
t.Log("\t" + strconv.Itoa(index+1) + ". " + item)
}

t.Log("")

t.Log("Found domains: ")
output_domains := DomainsOnly(string(data), true)
output_domains, err := DomainsOnly(string(data), true)

if err != nil {
t.Error(err)
}

for index, item := range output_domains {
t.Log("\t" + strconv.Itoa(index+1) + ". " + item)
}

t.Log("")

t.Log("Paired outputs: ")
output_pairs := SubdomainAndDomainPair(string(data), true)
output_pairs, err := SubdomainAndDomainPair(string(data), true)

if err != nil {
t.Error(err)
}

for index, item := range output_pairs {
output_pair_bytes, _ := json.Marshal(item)
t.Log("\t" + strconv.Itoa(index+1) + ". " + string(output_pair_bytes))
Expand Down

0 comments on commit f064c83

Please sign in to comment.