Fix `sphinx.ext.intersphinx crashes if non-string value is used for key of intersphinx_mapping`

This commit is contained in:
Takeshi KOMIYA 2016-05-23 12:11:10 +09:00
parent 20b3da5cf6
commit 9546fdaf5e
3 changed files with 9 additions and 4 deletions

View File

@ -58,6 +58,7 @@ Bugs fixed
* #2517: wrong bookmark encoding in PDF if using LuaLaTeX
* #2521: generated Makefile causes BSD make crashed if sphinx-build not found
* #2470: ``typing`` backport package causes autodoc errors with python 2.7
* ``sphinx.ext.intersphinx`` crashes if non-string value is used for key of `intersphinx_mapping`
Release 1.4.1 (released Apr 12, 2016)

View File

@ -33,7 +33,7 @@ import posixpath
from os import path
import re
from six import iteritems
from six import iteritems, string_types
from six.moves.urllib import parse, request
from docutils import nodes
from docutils.utils import relative_path
@ -271,7 +271,10 @@ def load_mappings(app):
if isinstance(value, tuple):
# new format
name, (uri, inv) = key, value
if not name.isalnum():
if not isinstance(name, string_types):
app.warn('intersphinx identifier %r is not string. Ignored' % name)
continue
elif not name.isalnum():
app.warn('intersphinx identifier %r is not alphanumeric' % name)
else:
# old format, no name

View File

@ -170,13 +170,14 @@ def test_load_mappings_warnings(tempdir, app, status, warning):
'py3k': ('https://docs.python.org/py3k/', inv_file),
'repoze.workflow': ('http://docs.repoze.org/workflow/', inv_file),
'django-taggit': ('http://django-taggit.readthedocs.org/en/latest/',
inv_file)
inv_file),
12345: ('http://www.sphinx-doc.org/en/stable/', inv_file),
}
app.config.intersphinx_cache_limit = 0
# load the inventory and check if it's done correctly
load_mappings(app)
assert warning.getvalue().count('\n') == 2
assert warning.getvalue().count('\n') == 3
class TestStripBasicAuth(unittest.TestCase):