Skip to content

Commit 9546fda

Browse files
committed
Fix sphinx.ext.intersphinx crashes if non-string value is used for key of intersphinx_mapping
1 parent 20b3da5 commit 9546fda

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Bugs fixed
5858
* #2517: wrong bookmark encoding in PDF if using LuaLaTeX
5959
* #2521: generated Makefile causes BSD make crashed if sphinx-build not found
6060
* #2470: ``typing`` backport package causes autodoc errors with python 2.7
61+
* ``sphinx.ext.intersphinx`` crashes if non-string value is used for key of `intersphinx_mapping`
6162

6263

6364
Release 1.4.1 (released Apr 12, 2016)

sphinx/ext/intersphinx.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from os import path
3434
import re
3535

36-
from six import iteritems
36+
from six import iteritems, string_types
3737
from six.moves.urllib import parse, request
3838
from docutils import nodes
3939
from docutils.utils import relative_path
@@ -271,7 +271,10 @@ def load_mappings(app):
271271
if isinstance(value, tuple):
272272
# new format
273273
name, (uri, inv) = key, value
274-
if not name.isalnum():
274+
if not isinstance(name, string_types):
275+
app.warn('intersphinx identifier %r is not string. Ignored' % name)
276+
continue
277+
elif not name.isalnum():
275278
app.warn('intersphinx identifier %r is not alphanumeric' % name)
276279
else:
277280
# old format, no name

tests/test_ext_intersphinx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,14 @@ def test_load_mappings_warnings(tempdir, app, status, warning):
170170
'py3k': ('https://docs.python.org/py3k/', inv_file),
171171
'repoze.workflow': ('http://docs.repoze.org/workflow/', inv_file),
172172
'django-taggit': ('http://django-taggit.readthedocs.org/en/latest/',
173-
inv_file)
173+
inv_file),
174+
12345: ('http://www.sphinx-doc.org/en/stable/', inv_file),
174175
}
175176

176177
app.config.intersphinx_cache_limit = 0
177178
# load the inventory and check if it's done correctly
178179
load_mappings(app)
179-
assert warning.getvalue().count('\n') == 2
180+
assert warning.getvalue().count('\n') == 3
180181

181182

182183
class TestStripBasicAuth(unittest.TestCase):

0 commit comments

Comments
 (0)