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 11:53:11 +0200
commit9afcad122467274ee4eb40d4aaf650985065480f (patch)
tree34ed5e10155008669f5550e18b4a545631c257b5
parent14bcdc86a29b0931f00e977705835e296b8d792e (diff)
downloadqutebrowser-9afcad122467274ee4eb40d4aaf650985065480f.tar.gz
qutebrowser-9afcad122467274ee4eb40d4aaf650985065480f.zip
Update content-disposition parsing workaround
Also adds workaround for https://github.com/python/cpython/issues/93010
-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 d13471277..a38cd358a 100644
--- a/qutebrowser/browser/webkit/http.py
+++ b/qutebrowser/browser/webkit/http.py
@@ -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)
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="{}"',