dairiki avatar dairiki committed 4e41f24

Intersphinx: parse inventories correctly when object names contain embedded spaces.

This is an issue, e.g., for (multi-word) glossary terms.

Comments (0)

Files changed (2)

sphinx/ext/intersphinx.py

 import urllib2
 import posixpath
 from os import path
+import re
 
 from docutils import nodes
 
         assert not buf
 
     for line in split_lines(read_chunks()):
-        name, type, prio, location, dispname = line.rstrip().split(None, 4)
+        # be careful to handle names with embedded spaces correctly
+        m = re.match(r'(?x)(.+?)\s+(\S*:\S*)\s+(\S+)\s+(\S+)\s+(.*)',
+                     line.rstrip())
+        if not m:
+            continue
+        name, type, prio, location, dispname = m.groups()
         if location.endswith(u'$'):
             location = location[:-1] + name
         location = join(uri, location)

tests/test_intersphinx.py

 module2 py:module 0 foo.html#module-$ -
 module1.func py:function 1 sub/foo.html#$ -
 CFunc c:function 2 cfunc.html#CFunc -
+a term std:term -1 glossary.html#term-a-term -
 '''.encode('utf-8'))
 
 
     assert invdata1['py:function']['module1.func'][2] == \
            '/util/sub/foo.html#module1.func'
     assert invdata1['c:function']['CFunc'][2] == '/util/cfunc.html#CFunc'
+    assert invdata1['std:term']['a term'][2] == \
+           '/util/glossary.html#term-a-term'
 
 
 @with_app(confoverrides={'extensions': 'sphinx.ext.intersphinx'})
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.