Florian Bruhin 2019-02-17 17:53:17 +01:00
parent d97a186992
commit 04764b9c39
2 changed files with 17 additions and 1 deletions

View File

@ -180,7 +180,21 @@ def _get_suggested_filename(path):
See https://bugreports.qt.io/browse/QTBUG-56978 See https://bugreports.qt.io/browse/QTBUG-56978
""" """
filename = os.path.basename(path) 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): if not qtutils.version_check('5.9', compiled=False):
# https://bugreports.qt.io/browse/QTBUG-58155 # https://bugreports.qt.io/browse/QTBUG-58155
filename = urllib.parse.unquote(filename) filename = urllib.parse.unquote(filename)

View File

@ -30,6 +30,8 @@ from helpers import utils
@pytest.mark.parametrize('path, expected', [ @pytest.mark.parametrize('path, expected', [
(os.path.join('subfolder', 'foo'), 'foo'), (os.path.join('subfolder', 'foo'), 'foo'),
('foo(1)', 'foo'), ('foo(1)', 'foo'),
('foo (1)', 'foo'),
('foo - 1970-01-01T00:00:00.000Z', 'foo'),
('foo(a)', 'foo(a)'), ('foo(a)', 'foo(a)'),
('foo1', 'foo1'), ('foo1', 'foo1'),
pytest.param('foo%20bar', 'foo bar', marks=utils.qt58), pytest.param('foo%20bar', 'foo bar', marks=utils.qt58),