summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-05-24 11:53:11 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-05-24 16:46:15 +0200
commit4a5b786802df9768eb19bded1cdab53dabd94ebb (patch)
tree66cd2b47258d861685583ef028459be58ff4dd04
parentfb34ab066e7ad0fff73c8768c5a70a4886970023 (diff)
downloadqutebrowser-4a5b786802df9768eb19bded1cdab53dabd94ebb.tar.gz
qutebrowser-4a5b786802df9768eb19bded1cdab53dabd94ebb.zip
Update content-disposition parsing workaround
Also adds workaround for https://github.com/python/cpython/issues/93010 (cherry picked from commit 9afcad122467274ee4eb40d4aaf650985065480f)
-rw-r--r--qutebrowser/browser/webkit/http.py7
-rw-r--r--tests/unit/browser/webkit/http/test_http.py15
2 files changed, 20 insertions, 2 deletions
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="{}"',