Skip to content

Commit

Permalink
removed unique flag
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4f53 committed Aug 10, 2024
1 parent dd34651 commit 0d9581d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
24 changes: 6 additions & 18 deletions textsubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/weppos/publicsuffix-go/publicsuffix"
)

var removeDuplicates = true

func removeDuplicateItems(items []string) []string {
encountered := make(map[string]bool)
result := []string{}
Expand Down Expand Up @@ -132,9 +130,8 @@ func getSubdomains(text string, breakFused bool) ([]string, error) {
// Returns: only the subdomains (subdomain.example.com) as a list of strings
// Inputs:
// text (string) -> The text to parse
// removeDuplicates (bool) -> return only unique names
// breakFused (bool) -> try and split fused subdomains (e.g. www.0x4f.iniforgot.apple.com becomes [www.0x4f.in iforgot.apple.com])
func SubdomainsOnly(text string, removeDuplicates bool, breakFused bool) ([]string, error) {
func SubdomainsOnly(text string, breakFused bool) ([]string, error) {

var results []string

Expand Down Expand Up @@ -162,9 +159,7 @@ func SubdomainsOnly(text string, removeDuplicates bool, breakFused bool) ([]stri
results = append(results, item)
}

if removeDuplicates {
results = removeDuplicateItems(results)
}
results = removeDuplicateItems(results)

}

Expand All @@ -175,9 +170,8 @@ func SubdomainsOnly(text string, removeDuplicates bool, breakFused bool) ([]stri
// Returns: only the domains (example.com) as a list of strings
// Inputs:
// text (string) -> The text to parse
// removeDuplicates (bool) -> return only unique names
// breakFused (bool) -> try and split fused domains (e.g. 0x4f.inapple.com becomes [0x4f.in apple.com])
func DomainsOnly(text string, removeDuplicates bool, breakFused bool) ([]string, error) {
func DomainsOnly(text string, breakFused bool) ([]string, error) {

var results []string

Expand All @@ -203,10 +197,7 @@ func DomainsOnly(text string, removeDuplicates bool, breakFused bool) ([]string,

results = append(results, domain)

if removeDuplicates {
results = removeDuplicateItems(results)
}

results = removeDuplicateItems(results)
}

return results, nil
Expand All @@ -222,10 +213,9 @@ type SubAndDom struct {
// {subdomain: subdomain.example.com, domain: example.com} as a list of a struct of strings
// Inputs:
// text (string) -> The text to parse
// removeDuplicates (bool) -> return only unique names
// keepDomains (bool) -> return domain even if domain does not contain a subdomain
// breakFused (bool) -> try and split fused subdomains and domains (e.g. www.0x4f.iniforgot.apple.com becomes [www.0x4f.in iforgot.apple.com])
func SubdomainAndDomainPair(text string, removeDuplicates bool, keepDomains bool, breakFused bool) ([]SubAndDom, error) {
func SubdomainAndDomainPair(text string, keepDomains bool, breakFused bool) ([]SubAndDom, error) {

var results []SubAndDom
subdomains, err := getSubdomains(text, breakFused)
Expand Down Expand Up @@ -255,9 +245,7 @@ func SubdomainAndDomainPair(text string, removeDuplicates bool, keepDomains bool

results = append(results, pair)

if removeDuplicates {
results = removeDuplicateSubAndDoms(results)
}
results = removeDuplicateSubAndDoms(results)

}

Expand Down
6 changes: 3 additions & 3 deletions textsubs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestMyFunction(t *testing.T) {
}

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

if err != nil {
t.Error(err)
Expand All @@ -30,7 +30,7 @@ func TestMyFunction(t *testing.T) {
t.Log("")

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

if err != nil {
t.Error(err)
Expand All @@ -43,7 +43,7 @@ func TestMyFunction(t *testing.T) {
t.Log("")

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

if err != nil {
t.Error(err)
Expand Down

0 comments on commit 0d9581d

Please sign in to comment.