diff --git a/tests/checker/data/http_anchor.html.result b/tests/checker/data/http_anchor.html.result index b9ebf0c7..d2fb5c25 100644 --- a/tests/checker/data/http_anchor.html.result +++ b/tests/checker/data/http_anchor.html.result @@ -7,7 +7,7 @@ url http_anchor.html#bad cache key http://localhost:%(port)d/%(datadir)s/http_anchor.html#bad real url http://localhost:%(port)d/%(datadir)s/http_anchor.html#bad name a_bad -warning Anchor `bad' not found. Available anchors: `good'. +warning Anchor `bad' (decoded: `bad') not found. Available anchors: `good'. valid url http_anchor.html#good diff --git a/tests/checker/data/urlencoding_anchor.html b/tests/checker/data/urlencoding_anchor.html new file mode 100644 index 00000000..c8b059c4 --- /dev/null +++ b/tests/checker/data/urlencoding_anchor.html @@ -0,0 +1,25 @@ + +Good target +Needs-encoded target #1 +Needs-encoded target #2 +Target for partially-encoded testing + + +No anchor, will not be tested +Good anchor +Bad anchor + + +Non-encoded anchor +Partially-encoded version of the same anchor +Fully-encoded version of the same anchor + + +Distinct encoded anchor + + +Bad encoded anchor, partially encoded +Bad encoded anchor, fully encoded + + +Partially-encoded anchor, for testing diff --git a/tests/checker/data/urlencoding_anchor.html.file.result b/tests/checker/data/urlencoding_anchor.html.file.result new file mode 100644 index 00000000..88f86c13 --- /dev/null +++ b/tests/checker/data/urlencoding_anchor.html.file.result @@ -0,0 +1,42 @@ +url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html +cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html +real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html +valid + +url urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_%%28and%%E2%%80%%94em-dashes%%29 +cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +name Distinct encoded anchor +valid + +url urlencoding_anchor.html#bad +cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad +real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad +name Bad anchor +warning Anchor `bad' (decoded: `bad') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'. +valid + +url urlencoding_anchor.html#bad_|_%%28and%%E2%%80%%94em-dashes%%29 +cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes) +real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes) +name Bad encoded anchor, partially encoded +warning Anchor `bad_%%7C_(and%%E2%%80%%94em-dashes)' (decoded: `bad_|_(and—em-dashes)') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'. +valid + +url urlencoding_anchor.html#good +cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#good +real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#good +name Good anchor +valid + +url urlencoding_anchor.html#partially_%%7C_(encoded_em—dash) +cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash) +real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash) +name Partially-encoded anchor, for testing +valid + +url urlencoding_anchor.html#with_pipes_|_and_parentheses_(and—em-dashes) +cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +name Non-encoded anchor +valid diff --git a/tests/checker/data/urlencoding_anchor.html.result b/tests/checker/data/urlencoding_anchor.html.result new file mode 100644 index 00000000..4793690c --- /dev/null +++ b/tests/checker/data/urlencoding_anchor.html.result @@ -0,0 +1,42 @@ +url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html +cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html +real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html +valid + +url urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_%%28and%%E2%%80%%94em-dashes%%29 +cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +name Distinct encoded anchor +valid + +url urlencoding_anchor.html#bad +cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad +real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad +name Bad anchor +warning Anchor `bad' (decoded: `bad') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'. +valid + +url urlencoding_anchor.html#bad_|_%%28and%%E2%%80%%94em-dashes%%29 +cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes) +real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes) +name Bad encoded anchor, partially encoded +warning Anchor `bad_%%7C_(and%%E2%%80%%94em-dashes)' (decoded: `bad_|_(and—em-dashes)') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'. +valid + +url urlencoding_anchor.html#good +cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#good +real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#good +name Good anchor +valid + +url urlencoding_anchor.html#partially_%%7C_(encoded_em—dash) +cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash) +real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash) +name Partially-encoded anchor, for testing +valid + +url urlencoding_anchor.html#with_pipes_|_and_parentheses_(and—em-dashes) +cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes) +name Non-encoded anchor +valid diff --git a/tests/checker/test_anchor.py b/tests/checker/test_anchor.py index df981cec..097e6a2d 100644 --- a/tests/checker/test_anchor.py +++ b/tests/checker/test_anchor.py @@ -20,22 +20,23 @@ from . import LinkCheckTest from .httpserver import HttpServerTest -class TestAnchor(LinkCheckTest): +class TestFileAnchor(LinkCheckTest): """ - Test anchor checking of HTML pages. + Test anchor checking of HTML files. """ - def test_anchor(self): + def test_anchor_file(self): confargs = {"enabledplugins": ["AnchorCheck"]} anchor = "broken" url = "file://%(curdir)s/%(datadir)s/anchor.html#%(anchor)s" % self.get_attrs( anchor=anchor) nurl = self.norm(url) resultlines = [ - "url %s" % url, - "cache key %s" % nurl, - "real url %s" % nurl, - "warning Anchor `%s' not found. Available anchors: `myid:'." % anchor, + f"url {url}", + f"cache key {nurl}", + f"real url {nurl}", + f"warning Anchor `{anchor}' (decoded: `{anchor}') not found." + " Available anchors: `myid:'.", "valid", ] self.direct(url, resultlines, confargs=confargs) @@ -46,11 +47,35 @@ class TestHttpAnchor(HttpServerTest): Test checking of HTML pages containing links to anchors served over http. """ - def test_anchor_html(self): + def test_anchor_http(self): confargs = dict(enabledplugins=["AnchorCheck"], recursionlevel=1) self.file_test("http_anchor.html", confargs=confargs) +class TestEncodedAnchors(HttpServerTest): + """Test HTML pages containing urlencoded links to anchors""" + + def test_anchor_encoded_http(self): + """ + http:// + """ + confargs = dict(enabledplugins=["AnchorCheck"], recursionlevel=1) + self.file_test("urlencoding_anchor.html", confargs=confargs) + + def test_anchor_encoded_file(self): + """ + file:// + This should have identical behavior as http:// + """ + filename = "urlencoding_anchor.html" + confargs = {"enabledplugins": ["AnchorCheck"]} + url = "file://%(curdir)s/%(datadir)s/%(filename)s" % self.get_attrs( + filename=filename) + # get results from the special result file that has `.file.` in its name + resultlines = self.get_resultlines(f"{filename}.file") + self.direct(url, resultlines, recursionlevel=1, confargs=confargs) + + class TestAnchorsAcrossMultipleFiles(LinkCheckTest): """Test anchors when there are multiple files"""