diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index c7eb367af..5b2f7153b 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -372,10 +372,15 @@ def get_path_if_valid(pathstr, cwd=None, relative=False, check_exists=False): path = None if check_exists: - if path is not None and os.path.exists(path): - log.url.debug("URL is a local file") - else: - path = None + if path is not None: + try: + if os.path.exists(path): + log.url.debug("URL is a local file") + except UnicodeEncodeError: + log.url.debug( + "URL contains characters which are not present in the " \ + "current locale") + path = None return path diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index ef97d5317..ff8f91ad6 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -70,7 +70,7 @@ def temp_basedir_env(tmpdir, short_tmpdir): @pytest.mark.linux -def test_ascii_locale(request, server, tmpdir, quteproc_new): +def test_downloads_with_ascii_locale(request, server, tmpdir, quteproc_new): """Test downloads with LC_ALL=C set. https://github.com/qutebrowser/qutebrowser/issues/908 @@ -102,6 +102,35 @@ def test_ascii_locale(request, server, tmpdir, quteproc_new): assert (tmpdir / '?-issue908.bin').exists() +@pytest.mark.linux +def test_open_with_ascii_locale(request, server, tmpdir, quteproc_new): + """Test opening non-ascii URL with LC_ALL=C set. + + https://github.com/qutebrowser/qutebrowser/issues/1450 + """ + args = ['--temp-basedir'] + _base_args(request.config) + quteproc_new.start(args, env={'LC_ALL': 'C'}) + + # Test opening a file whose name contains non-ascii characters. + # No exception thrown means test success. + url = 'file:///föö.html' + quteproc_new.send_cmd(':open {}'.format(url)) + quteproc_new.wait_for(category='url', + message='URL contains characters *') + + +@pytest.mark.linux +def test_open_command_line_with_ascii_locale(request, server, tmpdir, quteproc_new): + """Test opening file from the command line with a non-ascii name with LC_ALL=C set. + + https://github.com/qutebrowser/qutebrowser/issues/1450 + """ + # The file does not actually have to exist because the relevant checks will + # all be called. No exception thrown means test success. + args = ['--temp-basedir'] + _base_args(request.config) + ['/home/user/föö.html'] + quteproc_new.start(args, env={'LC_ALL': 'C'}) + + @pytest.mark.linux def test_misconfigured_user_dirs(request, server, temp_basedir_env, tmpdir, quteproc_new):