diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index a03faa07f..81768978d 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 . -"""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()