From 04764b9c39ef082784c7d5ca4457b4647deff7f8 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 17 Feb 2019 17:53:17 +0100 Subject: [PATCH] Adjust filename suffix matching for Qt 5.12 https://codereview.qt-project.org/#/c/247517/ https://chromium-review.googlesource.com/c/chromium/src/+/1278137 https://cs.chromium.org/chromium/src/base/time/time_to_iso8601.cc Fixes #4478 Fixes #4580 --- .../browser/webengine/webenginedownloads.py | 16 +++++++++++++++- .../browser/webengine/test_webenginedownloads.py | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/webengine/webenginedownloads.py b/qutebrowser/browser/webengine/webenginedownloads.py index 6dde42070..077ea775b 100644 --- a/qutebrowser/browser/webengine/webenginedownloads.py +++ b/qutebrowser/browser/webengine/webenginedownloads.py @@ -180,7 +180,21 @@ def _get_suggested_filename(path): See https://bugreports.qt.io/browse/QTBUG-56978 """ filename = os.path.basename(path) - filename = re.sub(r'\([0-9]+\)(?=\.|$)', '', filename) + + suffix_re = re.compile(r""" + \ ? # Optional space between filename and suffix + ( + # Numerical suffix + \([0-9]+\) + | + # ISO-8601 suffix + # https://cs.chromium.org/chromium/src/base/time/time_to_iso8601.cc + \ -\ \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z + ) + (?=\.|$) # Begin of extension, or filename without extension + """, re.VERBOSE) + + filename = suffix_re.sub('', filename) if not qtutils.version_check('5.9', compiled=False): # https://bugreports.qt.io/browse/QTBUG-58155 filename = urllib.parse.unquote(filename) diff --git a/tests/unit/browser/webengine/test_webenginedownloads.py b/tests/unit/browser/webengine/test_webenginedownloads.py index a34962522..4ca447f56 100644 --- a/tests/unit/browser/webengine/test_webenginedownloads.py +++ b/tests/unit/browser/webengine/test_webenginedownloads.py @@ -30,6 +30,8 @@ from helpers import utils @pytest.mark.parametrize('path, expected', [ (os.path.join('subfolder', 'foo'), 'foo'), ('foo(1)', 'foo'), + ('foo (1)', 'foo'), + ('foo - 1970-01-01T00:00:00.000Z', 'foo'), ('foo(a)', 'foo(a)'), ('foo1', 'foo1'), pytest.param('foo%20bar', 'foo bar', marks=utils.qt58),