Repository: raviqqe/muffet (go)

Issue:
muffet treats preconnect hrefs like links
Websites often have code like this

```html
<link rel="preconnect" href="https://fonts.googleapis.com">
```
in order to increase performance. `https://fonts.googleapis.com` returns 404 but the HTML code is still valid and should not be checked by muffet. 


Is this a unknown issue or am I doing something wrong with muffet?  
I am willing to implement a fix for this, just lmk.

Pull request:
don't follow preconnect and dns-prefetch links
Fixes #391 

Patch:
diff --git a/link_finder.go b/link_finder.go
index 43cf934..beee40c 100644
--- a/link_finder.go
+++ b/link_finder.go
@@ -40,6 +40,16 @@ func (f linkFinder) Find(n *html.Node, base *url.URL) map[string]error {
 		_, ok := atomToAttributes[n.DataAtom]
 		return ok
 	}) {
+
+		// https://github.com/raviqqe/muffet/issues/391
+		// preconnect and dns-prefetch hrefs are not http resources
+		if n.DataAtom == atom.Link {
+			rel := scrape.Attr(n, "rel")
+			if rel == "preconnect" || rel == "dns-prefetch" {
+				continue
+			}
+		}
+
 		for _, a := range atomToAttributes[n.DataAtom] {
 			ss := f.parseLinks(n, a)
 


Test patch:
diff --git a/link_finder_test.go b/link_finder_test.go
index 20a3072..7980c5f 100644
--- a/link_finder_test.go
+++ b/link_finder_test.go
@@ -217,6 +217,36 @@ func TestLinkFinderIgnoreMetaTags(t *testing.T) {
 	assert.Len(t, ls, 0)
 }
 
+func TestLinkFinderIgnorePreconnect(t *testing.T) {
+	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},
+		{`<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},
+	} {
+		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)
 }