mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #2990: linkcheck raises "Can't convert 'bytes' object to str implicitly" error if linkcheck_anchors enabled
This commit is contained in:
parent
4c7bec6460
commit
42604a1ff6
@ -51,6 +51,7 @@ class AnchorCheckParser(HTMLParser):
|
||||
for key, value in attrs:
|
||||
if key in ('id', 'name') and value == self.search_anchor:
|
||||
self.found = True
|
||||
break
|
||||
|
||||
|
||||
def check_anchor(response, anchor):
|
||||
@ -61,7 +62,7 @@ def check_anchor(response, anchor):
|
||||
try:
|
||||
# Read file in chunks. If we find a matching anchor, we break
|
||||
# the loop early in hopes not to have to download the whole thing.
|
||||
for chunk in response.iter_content():
|
||||
for chunk in response.iter_content(chunk_size=4096, decode_unicode=True):
|
||||
parser.feed(chunk)
|
||||
if parser.found:
|
||||
break
|
||||
|
4
tests/roots/test-linkcheck/conf.py
Normal file
4
tests/roots/test-linkcheck/conf.py
Normal file
@ -0,0 +1,4 @@
|
||||
master_doc = 'links'
|
||||
source_suffix = '.txt'
|
||||
exclude_patterns = ['_build']
|
||||
linkcheck_anchors = True
|
4
tests/roots/test-linkcheck/links.txt
Normal file
4
tests/roots/test-linkcheck/links.txt
Normal file
@ -0,0 +1,4 @@
|
||||
This is from CPython documentation.
|
||||
|
||||
* Also, if there is a `default namespace <https://www.w3.org/TR/2006/REC-xml-names-20060816/#defaulting>`__, that full URI gets prepended to all of the non-prefixed tags.
|
||||
* The `SSMEDIAN <https://help.gnome.org/users/gnumeric/stable/gnumeric.html#gnumeric-function-SSMEDIAN>`_ function in the Gnome Gnumeric spreadsheet.
|
25
tests/test_build_linkcheck.py
Normal file
25
tests/test_build_linkcheck.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_build_linkcheck
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Test the build process with manpage builder with the test root.
|
||||
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from util import with_app
|
||||
|
||||
|
||||
@with_app('linkcheck', testroot='linkcheck', freshenv=True)
|
||||
def test_all(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
assert (app.outdir / 'output.txt').exists()
|
||||
content = (app.outdir / 'output.txt').text()
|
||||
|
||||
# expect all ok
|
||||
assert not content
|
||||
|
Loading…
Reference in New Issue
Block a user