Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't follow preconnect and dns-prefetch links #392

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions link_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
_, ok := atomToAttributes[n.DataAtom]
return ok
}) {

// https://github.com/raviqqe/muffet/issues/391
// preconnect and dns-prefetch hrefs are not http resources

Check warning on line 45 in link_finder.go

View workflow job for this annotation

GitHub Actions / spell_check

Unknown word (preconnect)
if n.DataAtom == atom.Link {
rel := scrape.Attr(n, "rel")
if rel == "preconnect" || rel == "dns-prefetch" {

Check warning on line 48 in link_finder.go

View workflow job for this annotation

GitHub Actions / spell_check

Unknown word (preconnect)
continue
}
}

for _, a := range atomToAttributes[n.DataAtom] {
ss := f.parseLinks(n, a)

Expand Down
30 changes: 30 additions & 0 deletions link_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,36 @@
assert.Len(t, ls, 0)
}

func TestLinkFinderIgnorePreconnect(t *testing.T) {

Check warning on line 220 in link_finder_test.go

View workflow job for this annotation

GitHub Actions / spell_check

Unknown word (Preconnect)
b, err := url.Parse("https://localhost")
assert.Nil(t, err)

for _, c := range []struct {
html string
linkCount int
}{
{`<link rel="preconnect" href="https://fonts.googleapis.com">`, 0},

Check warning on line 228 in link_finder_test.go

View workflow job for this annotation

GitHub Actions / spell_check

Unknown word (preconnect)
{`<link rel="dns-prefetch" href="https://fonts.googleapis.com">`, 0},
{`<link rel="dns-prefetch" href="https://fonts.googleapis.com"><link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,300;0,400;0,700;1,400&amp;family=Source+Sans+Pro:ital,wght@0,300;0,400;0,600;1,400&amp;display=swap" rel="stylesheet">`, 1},

Check warning on line 230 in link_finder_test.go

View workflow job for this annotation

GitHub Actions / spell_check

Unknown word (stylesheet)
} {
n, err := html.Parse(strings.NewReader(htmlWithBody(c.html)))
assert.Nil(t, err)

s, e := 0, 0

for _, err := range newTestLinkFinder().Find(n, b) {
if err == nil {
s++
} else {
e++
}
}

assert.Equal(t, c.linkCount, s)
assert.Equal(t, 0, e)
}
}

func htmlWithBody(b string) string {
return fmt.Sprintf(`<html><body>%v</body></html>`, b)
}
Expand Down
Loading