Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where opening a file whose name contains characters not present in locale would cause a crash. #3177

Merged
merged 4 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions qutebrowser/utils/urlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 " \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the \ here, inside parentheses whitespace is ignored by Python.

"current locale")
path = None

return path

Expand Down
31 changes: 30 additions & 1 deletion tests/end2end/test_invocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to also pass a file to open here on the commandline, as that seemed to trigger a slightly different bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't crash, but just shows URL_NOT_FOUND, which I think would be correct. Regardless, I added a test for it in case that breaks in the future.

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):
Expand Down