Merge "Ignore Range values like "bytes=--0""

This commit is contained in:
Jenkins
2016-11-05 02:27:29 +00:00
committed by Gerrit Code Review
2 changed files with 6 additions and 2 deletions

View File

@@ -485,8 +485,10 @@ class Range(object):
else:
start = None
if end:
# when end contains non numeric value, this also causes
# ValueError
# We could just rely on int() raising the ValueError, but
# this catches things like '--0'
if not end.isdigit():
raise ValueError('Invalid Range header: %s' % headerval)
end = int(end)
if end < 0:
raise ValueError('Invalid Range header: %s' % headerval)

View File

@@ -250,6 +250,7 @@ class TestRange(unittest.TestCase):
"""
_assert_invalid_range(None)
_assert_invalid_range('nonbytes=0-')
_assert_invalid_range('nonbytes=foobar,10-2')
_assert_invalid_range('bytes=5-3')
_assert_invalid_range('bytes=-')
@@ -260,6 +261,7 @@ class TestRange(unittest.TestCase):
_assert_invalid_range('bytes=nonumber-5')
_assert_invalid_range('bytes=nonumber')
_assert_invalid_range('bytes=--1')
_assert_invalid_range('bytes=--0')
class TestMatch(unittest.TestCase):