mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
parselinenos() raises out of range error
This commit is contained in:
parent
6b20c72521
commit
f1d4248eea
@ -266,11 +266,7 @@ class LiteralIncludeReader(object):
|
||||
raise ValueError(_('Cannot use "lineno-match" with a disjoint '
|
||||
'set of "lines"'))
|
||||
|
||||
# just ignore non-existing lines
|
||||
lines = [lines[n] for n in linelist if n < len(lines)]
|
||||
if not lines:
|
||||
raise ValueError(_('Line spec %r: no lines pulled from include file %r') %
|
||||
(linespec, self.filename))
|
||||
lines = [lines[n] for n in linelist]
|
||||
|
||||
return lines
|
||||
|
||||
|
@ -394,7 +394,7 @@ def parselinenos(spec, total):
|
||||
elif len(begend) == 2:
|
||||
start, end = begend
|
||||
start = int(start or 1) # left half open (cf. -10)
|
||||
end = int(end or total) # right half open (cf. 10-)
|
||||
end = int(end or max(start, total)) # right half open (cf. 10-)
|
||||
if start > end: # invalid range (cf. 10-1)
|
||||
raise ValueError
|
||||
items.extend(range(start - 1, end))
|
||||
@ -402,6 +402,9 @@ def parselinenos(spec, total):
|
||||
raise ValueError
|
||||
except Exception:
|
||||
raise ValueError('invalid line number spec: %r' % spec)
|
||||
|
||||
if any(i >= total for i in items):
|
||||
raise ValueError('line number spec is out of range(0-%d): %r' % (total, spec))
|
||||
return items
|
||||
|
||||
|
||||
|
@ -114,3 +114,5 @@ def test_parselinenos():
|
||||
parselinenos('-', 10)
|
||||
with pytest.raises(ValueError):
|
||||
parselinenos('3-1', 10)
|
||||
with pytest.raises(ValueError):
|
||||
parselinenos('11-', 10)
|
||||
|
Loading…
Reference in New Issue
Block a user