Commits

Georg Brandl committed 6dde9e5

Closes #675: Fix IndexErrors when including nonexisting lines with :rst:dir:`literalinclude`.

  • Participants
  • Parent commits 5afc609

Comments (0)

Files changed (2)

 Release 1.0.8 (in development)
 ==============================
 
+* #675: Fix IndexErrors when including nonexisting lines with
+  :rst:dir:`literalinclude`.
+
 * #676: Respect custom function/method parameter separator strings.
 
 * #682: Fix JS incompatibility with jQuery >= 1.5.

File sphinx/directives/code.py

                 linelist = parselinenos(linespec, len(lines))
             except ValueError, err:
                 return [document.reporter.warning(str(err), line=self.lineno)]
-            lines = [lines[i] for i in linelist]
+            # just ignore nonexisting lines
+            nlines = len(lines)
+            lines = [lines[i] for i in linelist if i < nlines]
+            if not lines:
+                return [document.reporter.warning(
+                    'Line spec %r: no lines pulled from include file %r' %
+                    (linespec, filename), line=self.lineno)]
 
         startafter = self.options.get('start-after')
         endbefore  = self.options.get('end-before')