Georg Brandl avatar Georg Brandl committed 9974036

Fix #60: Don't crash for invalid index entries.

Comments (0)

Files changed (3)

+Release 0.5.1 (in development)
+==============================
+
+* Don't crash on empty index entries, only emit a warning.
+
+
 Release 0.5 (Nov 23, 2008) -- Birthday release!
 ===============================================
 

sphinx/directives/other.py

             # shorthand notation for single entries
             else:
                 for value in entry.split(','):
-                    ne.append(('single', value.strip(), targetid, value.strip()))
+                    value = value.strip()
+                    if not value:
+                        continue
+                    ne.append(('single', value, targetid, value))
     return [indexnode, targetnode]
 
 index_directive.arguments = (1, 0, 1)

sphinx/environment.py

                     pass
 
         for fn, entries in self.indexentries.iteritems():
-            # new entry types must be listed in directives.py!
+            # new entry types must be listed in directives/other.py!
             for type, string, tid, alias in entries:
                 if type == 'single':
                     try:
                         entry, subentry = string.split(';', 1)
                     except ValueError:
                         entry, subentry = string, ''
+                    if not entry:
+                        self.warn(fn, 'invalid index entry %r' % string)
+                        continue
                     add_entry(entry.strip(), subentry.strip())
                 elif type == 'pair':
-                    first, second = map(lambda x: x.strip(), string.split(';', 1))
+                    try:
+                        first, second = map(lambda x: x.strip(),
+                                            string.split(';', 1))
+                        if not first or not second:
+                            raise ValueError
+                    except ValueError:
+                        self.warn(fn, 'invalid pair index entry %r' % string)
+                        continue
                     add_entry(first, second)
                     add_entry(second, first)
                 elif type == 'triple':
-                    first, second, third = map(lambda x: x.strip(), string.split(';', 2))
+                    try:
+                        first, second, third = map(lambda x: x.strip(),
+                                                   string.split(';', 2))
+                        if not first or not second or not third:
+                            raise ValueError
+                    except ValueError:
+                        self.warn(fn, 'invalid triple index entry %r' % string)
+                        continue
                     add_entry(first, second+' '+third)
                     add_entry(second, third+', '+first)
                     add_entry(third, first+' '+second)
                 else:
-                    self.warn(fn, "unknown index entry type %r" % type)
+                    self.warn(fn, 'unknown index entry type %r' % type)
 
         newlist = new.items()
         newlist.sort(key=lambda t: t[0].lower())
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.