Update content-disposition parsing workaround

Also adds workaround for https://github.com/python/cpython/issues/93010
This commit is contained in:
Florian Bruhin 2022-05-24 11:53:11 +02:00
parent 14bcdc86a2
commit 9afcad1224
2 changed files with 20 additions and 2 deletions

View File

@ -89,13 +89,16 @@ class ContentDisposition:
try:
parsed = reg('Content-Disposition', decoded)
except IndexError: # pragma: no cover
# WORKAROUND for https://bugs.python.org/issue37491
# WORKAROUND for https://github.com/python/cpython/issues/81672
# Fixed in Python 3.7.5 and 3.8.0.
# Still getting failures on 3.10 on CI though
raise ContentDispositionError("Missing closing quote character")
except ValueError: # pragma: no cover
# WORKAROUND for https://bugs.python.org/issue42946
# WORKAROUND for https://github.com/python/cpython/issues/87112
raise ContentDispositionError("Non-ASCII digit")
except AttributeError:
# WORKAROUND for https://github.com/python/cpython/issues/93010
raise ContentDispositionError("Section number has an invalid leading 0")
if parsed.defects:
defects = list(parsed.defects)

View File

@ -44,6 +44,21 @@ def test_no_content_disposition(stubs, url, expected):
assert filename == expected
@pytest.mark.parametrize('value', [
# https://github.com/python/cpython/issues/87112
'inline; 0*²'.encode("iso-8859-1"),
# https://github.com/python/cpython/issues/81672
b'"',
# https://github.com/python/cpython/issues/93010
b'attachment; 0*00="foo"',
# FIXME: Should probably have more tests if this is still relevant after
# dropping QtWebKit.
])
def test_parse_content_disposition_invalid(value):
with pytest.raises(http.ContentDispositionError):
http.ContentDisposition.parse(value)
@pytest.mark.parametrize('template', [
'{}',
'attachment; filename="{}"',