Skip to content

Commit

Permalink
Merge pull request #18 from pzaino/develop
Browse files Browse the repository at this point in the history
fixed a bug found during integration tests
  • Loading branch information
pzaino authored Jan 22, 2024
2 parents 97c1dff + b3ea7fb commit c3ad40b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions pkg/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,20 @@ func isExternalLink(sourceURL, linkURL string) bool {

// Takes the substring that correspond to the 1st and 2nd level domain (e.g., google.com)
// regardless the number of subdomains
var srcDomainName string
srcFqdnArr := strings.Split(sourceParsed.Hostname(), ".")
srcDomainName := strings.Join(srcFqdnArr[len(srcFqdnArr)-2:], ".")
if len(srcFqdnArr) < 3 {
srcDomainName = strings.Join(srcFqdnArr, ".")
} else {
srcDomainName = strings.Join(srcFqdnArr[len(srcFqdnArr)-2:], ".")
}
linkFqdnArr := strings.Split(linkParsed.Hostname(), ".")
linkDomainName := strings.Join(linkFqdnArr[len(linkFqdnArr)-2:], ".")
var linkDomainName string
if len(linkFqdnArr) < 3 {
linkDomainName = strings.Join(linkFqdnArr, ".")
} else {
linkDomainName = strings.Join(linkFqdnArr[len(linkFqdnArr)-2:], ".")
}

// Compare hostnames
return srcDomainName != linkDomainName
Expand Down
3 changes: 2 additions & 1 deletion pkg/crawler/crawler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestExtractLinks(t *testing.T) {
}
}

func Test_isExternalLink(t *testing.T) {
func TestIsExternalLink(t *testing.T) {
type args struct {
sourceURL string
linkURL string
Expand All @@ -57,6 +57,7 @@ func Test_isExternalLink(t *testing.T) {
{"test3", args{"https://www.google.com", "https://www.google.com/test/test"}, false},
{"test4", args{"https://www.example.com", "https://www.google.com/test/test/test"}, true},
{"test5", args{"https://data.example.com", "https://www.example.com"}, false},
{"test6", args{"www.apps.com", "javascript:void(0)"}, false},
}

for _, tt := range tests {
Expand Down

0 comments on commit c3ad40b

Please sign in to comment.