Ignore Range values like "bytes=--0"

This is consistent with what we already do for other
semantically-invalid values like "bytes=--1". Previously, we would
return a 416 Requested Range Not Satisfiable response like we do for the
semantically-valid-but-not-really-meaningful "bytes=-0"

Change-Id: I932b42406c9a5ee7eaa6978a655e61022a957415
This commit is contained in:
Tim Burke
2016-10-29 18:29:48 +02:00
parent e55f3ad203
commit c91ca5335f
2 changed files with 6 additions and 2 deletions

View File

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

View File

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