diff --git a/qutebrowser/browser/webkit/http.py b/qutebrowser/browser/webkit/http.py index 4b6a03218..f36ca14ec 100644 --- a/qutebrowser/browser/webkit/http.py +++ b/qutebrowser/browser/webkit/http.py @@ -89,12 +89,15 @@ 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. 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) diff --git a/tests/unit/browser/webkit/http/test_http.py b/tests/unit/browser/webkit/http/test_http.py index 4db78f4ff..d50f1c277 100644 --- a/tests/unit/browser/webkit/http/test_http.py +++ b/tests/unit/browser/webkit/http/test_http.py @@ -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="{}"',