Skip to content

Commit

Permalink
Merge pull request #166 from wjdp/hash-in-pre
Browse files Browse the repository at this point in the history
Stop ignoring the content of pre / code tags
  • Loading branch information
wjdp authored Apr 30, 2021
2 parents 2409cf0 + b679f7a commit b78570d
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 18 deletions.
2 changes: 0 additions & 2 deletions htmldoc/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func (doc *Document) parseNode(n *html.Node) {
case "base":
// Set BasePath from <base> tag
doc.BasePath = path.Join(doc.BasePath, GetAttr(n.Attr, "href"))
case "pre", "code":
return // Everything within these elements is not to be interpreted
}
case html.ErrorNode:
fmt.Printf("%+v\n", n)
Expand Down
2 changes: 1 addition & 1 deletion htmldoc/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestDocumentNodesOfInterest(t *testing.T) {
}
doc.Init()
doc.Parse()
assert.Equals(t, "nodes of interest", len(doc.NodesOfInterest), 4)
assert.Equals(t, "nodes of interest", len(doc.NodesOfInterest), 12)
}

func TestDocumentBasePathDefault(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions htmltest/check-img_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ func TestImageAltIgnoreMissingWithBlank(t *testing.T) {
tExpectIssueCount(t, hT, 0)
}

func TestImagePre(t *testing.T) {
// works for broken images within pre & code
func TestBrokenImagePre(t *testing.T) {
// we no longer ignore image issues in pre / code tags
hT := tTestFile("fixtures/images/badImagesInPre.html")
tExpectIssueCount(t, hT, 0)
tExpectIssueCount(t, hT, 16)
}

func TestImageUsemap(t *testing.T) {
Expand Down
19 changes: 14 additions & 5 deletions htmltest/check-link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ func TestAnchorHashBrokenIgnore(t *testing.T) {
tExpectIssueCount(t, hT2, 0)
}

func TestAnchorHashInPre163(t *testing.T) {
// passes for valid self hash
hT := tTestFile("fixtures/links/hash-in-pre-163.html")
tExpectIssueCount(t, hT, 0)
}

func TestAnchorDirectoryRootResolve(t *testing.T) {
// properly resolves implicit /index.html in link paths
hT := tTestFile("fixtures/links/linkToFolder.html")
Expand Down Expand Up @@ -609,15 +615,18 @@ func TestLinkRelDnsPrefetch(t *testing.T) {
}

func TestAnchorPre(t *testing.T) {
// works for broken anchors within pre & code
hT := tTestFile("fixtures/links/anchors_in_pre.html")
tExpectIssueCount(t, hT, 0)
// catches broken links when inside pre or code tags
hT := tTestFileOpts("fixtures/links/anchors_in_pre.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 2)
tExpectIssue(t, hT, "Non-OK status", 2)
}

func TestLinkPre(t *testing.T) {
// works for broken link within pre & code
// catches broken links when inside pre or code tags
hT := tTestFile("fixtures/links/links_in_pre.html")
tExpectIssueCount(t, hT, 0)
tExpectIssueCount(t, hT, 2)
tExpectIssue(t, hT, "href blank", 2)
}

func TestAnchorHashQueryBroken(t *testing.T) {
Expand Down
10 changes: 7 additions & 3 deletions htmltest/check-script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ func TestScriptContentAbsent(t *testing.T) {
}

func TestScriptInPre(t *testing.T) {
// works for broken script within pre & code
hT := tTestFile("fixtures/scripts/script_in_pre.html")
tExpectIssueCount(t, hT, 0)
// catches broken links when inside pre or code tags
hT := tTestFileOpts("fixtures/scripts/script_in_pre.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 4)
tExpectIssue(t, hT, "Non-OK status", 2)
tExpectIssue(t, hT, "script content missing", 2)

}

func TestScriptSrcIgnore(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions htmltest/fixtures/images/badImagesInPre.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<img src="./gpl.png" />
<img src="./madeup.xyz" />
<img src=" " />
<img src="http://website.com/image.bmp" />
<img alt=" " />
<img alt="" />
</pre>
Expand All @@ -11,7 +10,6 @@
<img src="./gpl.png" />
<img src="./madeup.xyz" />
<img src=" " />
<img src="http://website.com/image.bmp" />
<img alt=" " />
<img alt="" />
</code>
7 changes: 7 additions & 0 deletions htmltest/fixtures/links/hash-in-pre-163.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>

<pre><span id="A">1</span></pre>
<a href="#A">1</a>

<span id="B">2</span>
<a href="#B">2</a>
4 changes: 2 additions & 2 deletions htmltest/fixtures/scripts/script_in_pre.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<pre lang="html"><code><script src="https://embed.github.com/view/geojson/<username>/<repo>/<ref>/<path_to_file>"></script>
<pre lang="html"><code><script src="https://embed.github.invalid/view/geojson/<username>/<repo>/<ref>/<path_to_file>"></script>
</code></pre>

<pre><script></script></pre>

<code><script src="https://embed.github.com/view/geojson/<username>/<repo>/<ref>/<path_to_file>"></script>
<code><script src="https://embed.github.invalid/view/geojson/<username>/<repo>/<ref>/<path_to_file>"></script>
</code>

<code><script></script></code>
94 changes: 94 additions & 0 deletions htmltest/fixtures/vcr/links/anchors_in_pre.html.cassette
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"Name": "anchors_in_pre.html",
"Path": "fixtures/vcr/links",
"Tracks": [
{
"Request": {
"Method": "GET",
"URL": {
"Scheme": "http",
"Opaque": "",
"User": null,
"Host": "www.asdo3IRJ395295jsingrkrg4.com",
"Path": "",
"RawPath": "",
"ForceQuery": false,
"RawQuery": "",
"Fragment": "",
"RawFragment": ""
},
"Header": {
"Accept": [
"*/*"
],
"Range": [
"bytes=0-0"
],
"User-Agent": [
"htmltest/dev"
]
},
"Body": ""
},
"Response": {
"Status": "",
"StatusCode": 0,
"Proto": "",
"ProtoMajor": 0,
"ProtoMinor": 0,
"Header": null,
"Body": null,
"ContentLength": 0,
"TransferEncoding": null,
"Trailer": null,
"TLS": null
},
"ErrType": "*net.OpError",
"ErrMsg": "dial tcp: lookup www.asdo3IRJ395295jsingrkrg4.com: no such host"
},
{
"Request": {
"Method": "GET",
"URL": {
"Scheme": "http",
"Opaque": "",
"User": null,
"Host": "www.asdo3IRJ395295jsingrkrg4.com",
"Path": "",
"RawPath": "",
"ForceQuery": false,
"RawQuery": "",
"Fragment": "",
"RawFragment": ""
},
"Header": {
"Accept": [
"*/*"
],
"Range": [
"bytes=0-0"
],
"User-Agent": [
"htmltest/dev"
]
},
"Body": ""
},
"Response": {
"Status": "",
"StatusCode": 0,
"Proto": "",
"ProtoMajor": 0,
"ProtoMinor": 0,
"Header": null,
"Body": null,
"ContentLength": 0,
"TransferEncoding": null,
"Trailer": null,
"TLS": null
},
"ErrType": "*net.OpError",
"ErrMsg": "dial tcp: lookup www.asdo3IRJ395295jsingrkrg4.com: no such host"
}
]
}
94 changes: 94 additions & 0 deletions htmltest/fixtures/vcr/scripts/script_in_pre.html.cassette
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"Name": "script_in_pre.html",
"Path": "fixtures/vcr/scripts",
"Tracks": [
{
"Request": {
"Method": "GET",
"URL": {
"Scheme": "https",
"Opaque": "",
"User": null,
"Host": "embed.github.invalid",
"Path": "/view/geojson/\u003cusername\u003e/\u003crepo\u003e/\u003cref\u003e/\u003cpath_to_file\u003e",
"RawPath": "",
"ForceQuery": false,
"RawQuery": "",
"Fragment": "",
"RawFragment": ""
},
"Header": {
"Accept": [
"*/*"
],
"Range": [
"bytes=0-0"
],
"User-Agent": [
"htmltest/dev"
]
},
"Body": ""
},
"Response": {
"Status": "",
"StatusCode": 0,
"Proto": "",
"ProtoMajor": 0,
"ProtoMinor": 0,
"Header": null,
"Body": null,
"ContentLength": 0,
"TransferEncoding": null,
"Trailer": null,
"TLS": null
},
"ErrType": "*net.OpError",
"ErrMsg": "dial tcp: lookup embed.github.invalid: no such host"
},
{
"Request": {
"Method": "GET",
"URL": {
"Scheme": "https",
"Opaque": "",
"User": null,
"Host": "embed.github.invalid",
"Path": "/view/geojson/\u003cusername\u003e/\u003crepo\u003e/\u003cref\u003e/\u003cpath_to_file\u003e",
"RawPath": "",
"ForceQuery": false,
"RawQuery": "",
"Fragment": "",
"RawFragment": ""
},
"Header": {
"Accept": [
"*/*"
],
"Range": [
"bytes=0-0"
],
"User-Agent": [
"htmltest/dev"
]
},
"Body": ""
},
"Response": {
"Status": "",
"StatusCode": 0,
"Proto": "",
"ProtoMajor": 0,
"ProtoMinor": 0,
"Header": null,
"Body": null,
"ContentLength": 0,
"TransferEncoding": null,
"Trailer": null,
"TLS": null
},
"ErrType": "*net.OpError",
"ErrMsg": "dial tcp: lookup embed.github.invalid: no such host"
}
]
}

0 comments on commit b78570d

Please sign in to comment.