From d0372f1730e4d1d775ba4fdf818f0e70735b98c9 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 9 Dec 2016 07:08:51 +0100 Subject: [PATCH] Decode percent sequences in QtWebEngine downloads Fixes #2122. --- qutebrowser/browser/webengine/webenginedownloads.py | 2 ++ .../end2end/data/downloads/download with spaces.bin | Bin 0 -> 1 bytes tests/end2end/features/downloads.feature | 5 +++++ .../browser/webengine/test_webenginedownloads.py | 1 + 4 files changed, 8 insertions(+) create mode 100644 tests/end2end/data/downloads/download with spaces.bin diff --git a/qutebrowser/browser/webengine/webenginedownloads.py b/qutebrowser/browser/webengine/webenginedownloads.py index 8ce0cdc2e..e78e939e1 100644 --- a/qutebrowser/browser/webengine/webenginedownloads.py +++ b/qutebrowser/browser/webengine/webenginedownloads.py @@ -21,6 +21,7 @@ import re import os.path +import urllib import functools from PyQt5.QtCore import pyqtSlot, Qt @@ -135,6 +136,7 @@ def _get_suggested_filename(path): """ filename = os.path.basename(path) filename = re.sub(r'\([0-9]+\)$', '', filename) + filename = urllib.parse.unquote(filename) return filename diff --git a/tests/end2end/data/downloads/download with spaces.bin b/tests/end2end/data/downloads/download with spaces.bin new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d GIT binary patch literal 1 IcmZPo000310RR91 literal 0 HcmV?d00001 diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 14757c87a..b6a38da29 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -113,6 +113,11 @@ Feature: Downloading things from a website. And I wait for "Download drip finished" in the log Then the downloaded file drip should contain 128 bytes + Scenario: Downloading a file with spaces + When I open data/downloads/download with spaces.bin without waiting + And I wait until the download is finished + Then the downloaded file download with spaces.bin should exist + ## :download-retry Scenario: Retrying a failed download diff --git a/tests/unit/browser/webengine/test_webenginedownloads.py b/tests/unit/browser/webengine/test_webenginedownloads.py index 3cead0e97..fcd3c2adb 100644 --- a/tests/unit/browser/webengine/test_webenginedownloads.py +++ b/tests/unit/browser/webengine/test_webenginedownloads.py @@ -29,6 +29,7 @@ from qutebrowser.browser.webengine import webenginedownloads ('foo(1)', 'foo'), ('foo(a)', 'foo(a)'), ('foo1', 'foo1'), + ('foo%20bar', 'foo bar'), ]) def test_get_suggested_filename(path, expected): assert webenginedownloads._get_suggested_filename(path) == expected