-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from 3 commits
bdfb9c6
96eff65
f53d813
f67c445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea to log this as debug, the same way the other branch gets logged. |
||
|
||
return path | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,23 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_misconfigured_user_dirs(request, server, temp_basedir_env, | ||
tmpdir, quteproc_new): | ||
|
There was a problem hiding this comment.
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.