summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2016-04-10 20:16:10 +0200
committerFlorian Bruhin <git@the-compiler.org>2016-04-10 20:35:07 +0200
commit3521ee16e454a7e68c7203dedd369179f6104265 (patch)
treea20b2750e02e96afe43006f723b8e3746057b7d6
parentaf5cb36591842f3de9769aeb4ebf529f48226f98 (diff)
downloadqutebrowser-3521ee16e454a7e68c7203dedd369179f6104265.tar.gz
qutebrowser-3521ee16e454a7e68c7203dedd369179f6104265.zip
Fix downloading of non-ascii files with LC_ALL=C
Fixes #908.
-rw-r--r--qutebrowser/browser/downloads.py9
-rw-r--r--tests/integration/test_invocations.py22
2 files changed, 26 insertions, 5 deletions
diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py
index 21719df1e..01b188a4f 100644
--- a/qutebrowser/browser/downloads.py
+++ b/qutebrowser/browser/downloads.py
@@ -104,6 +104,11 @@ def create_full_filename(basename, filename):
Return:
The full absolute path, or None if filename creation was not possible.
"""
+ # Remove chars which can't be encoded in the filename encoding.
+ # See https://github.com/The-Compiler/qutebrowser/issues/427
+ encoding = sys.getfilesystemencoding()
+ filename = utils.force_encoding(filename, encoding)
+ basename = utils.force_encoding(basename, encoding)
if os.path.isabs(filename) and os.path.isdir(filename):
# We got an absolute directory from the user, so we save it under
# the default filename in that directory.
@@ -523,10 +528,6 @@ class DownloadItem(QObject):
"existing: {}, fileobj {}".format(
filename, self._filename, self.fileobj))
filename = os.path.expanduser(filename)
- # Remove chars which can't be encoded in the filename encoding.
- # See https://github.com/The-Compiler/qutebrowser/issues/427
- encoding = sys.getfilesystemencoding()
- filename = utils.force_encoding(filename, encoding)
self._filename = create_full_filename(self.basename, filename)
if self._filename is None:
# We only got a filename (without directory) or a relative path
diff --git a/tests/integration/test_invocations.py b/tests/integration/test_invocations.py
index c88462207..a13c6ac25 100644
--- a/tests/integration/test_invocations.py
+++ b/tests/integration/test_invocations.py
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
-"""Test starting qutebrowser with various commandline arguments."""
+"""Test starting qutebrowser with special arguments/environments."""
import pytest
@@ -51,3 +51,23 @@ def test_no_config(tmpdir, quteproc_new):
quteproc_new.start(args, env=env)
quteproc_new.send_cmd(':quit')
quteproc_new.wait_for_quit()
+
+
+@pytest.mark.linux
+def test_ascii_locale(httpbin, tmpdir, quteproc_new):
+ """Test downloads with LC_ALL=C set.
+
+ https://github.com/The-Compiler/qutebrowser/issues/908
+ """
+ args = ['--debug', '--no-err-windows', '--temp-basedir', 'about:blank']
+ quteproc_new.start(args, env={'LC_ALL': 'C'})
+ quteproc_new.set_setting('storage', 'download-directory', str(tmpdir))
+ quteproc_new.set_setting('storage', 'prompt-download-directory', 'false')
+ url = 'http://localhost:{port}/data/downloads/รค-issue908.bin'.format(
+ port=httpbin.port)
+ quteproc_new.send_cmd(':download {}'.format(url))
+ quteproc_new.send_cmd(':quit')
+ quteproc_new.wait_for_quit()
+
+ assert len(tmpdir.listdir()) == 1
+ assert (tmpdir / '?-issue908.bin').exists()