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
Conversation
present in locale would cause a crash. Fixes qutebrowser/qutebrowser/1450
If there is a respective test I could write then if someone tells me where it goes I'd be more than happy to make it. |
qutebrowser/utils/urlutils.py
Outdated
if os.path.exists(path): | ||
log.url.debug("URL is a local file") | ||
except UnicodeEncodeError: | ||
path = None |
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.
I think it's a good idea to log this as debug, the same way the other branch gets logged.
I took a look at this, but
dosen't seem to actually set the locale, so I can't find a way to trigger this under tox. Even running tox with LC_ALL=C dosen't seem to work for me. The actual test should be simple, something like:
But I don't know how to get this to reproduce reliably in tox. |
qutebrowser/utils/urlutils.py
Outdated
if os.path.exists(path): | ||
log.url.debug("URL is a local file") | ||
except UnicodeEncodeError: | ||
path = None | ||
else: | ||
path = None |
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 this else:
anymore as we just do if path is not None:
above now.
|
I don't have the latest Qt installed on my machine so I'm using travis to check that the test I wrote succeeds while I install it. |
log.url.debug("URL is a local file") | ||
except UnicodeEncodeError: | ||
log.url.debug( | ||
"URL contains characters which are not present in the " \ |
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.
|
||
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 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?
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.
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.
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.
I haven't had time to take a closer look yet, but this seems to break the entire testsuite on Travis. Can you take a look at that please?
@The-Compiler I'm having a lot of trouble getting the tests to actually run on my machine. According to the tox output, the tests are forcing the webengine but they just fail. Do I need a special build of qt/pyqt? |
Does it help if you run tox with |
I've also tried to make the entire testsuite run with diff --git a/pytest.ini b/pytest.ini
index 1dc9e3ba5..0cc5e49aa 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -26,6 +26,7 @@ markers =
no_invalid_lines: Don't fail on unparseable lines in end2end tests
issue2478: Tests which are broken on Windows with QtWebEngine, https://github.com/qutebrowser/qutebrowser/issues/2478
fake_os: Fake utils.is_* to a fake operating system
+ unicode_locale: Tests which need an unicode locale to work
qt_log_level_fail = WARNING
qt_log_ignore =
^SpellCheck: .*
diff --git a/tests/conftest.py b/tests/conftest.py
index 301658d56..0c28ed17b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -63,6 +63,8 @@ def _apply_platform_markers(config, item):
('no_ci', 'CI' in os.environ, "Skipped on CI."),
('issue2478', utils.is_windows and config.webengine,
"Broken with QtWebEngine on Windows"),
+ ('unicode_locale', sys.getfilesystemencoding() == 'ascii',
+ "Skipped because of ASCII locale"),
]
for searched_marker, condition, default_reason in markers:
diff --git a/tests/end2end/features/history.feature b/tests/end2end/features/history.feature
index 86e5d6f00..aa126c4f7 100644
--- a/tests/end2end/features/history.feature
+++ b/tests/end2end/features/history.feature
@@ -32,6 +32,7 @@ Feature: Page history
Then the history should contain:
http://localhost:(port)/data/title%20with%20spaces.html Test title
+ @unicode_locale
Scenario: History item with umlauts
When I open data/äöü.html
Then the history should contain:
diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py
index 1a91be2e0..921eb085a 100644
--- a/tests/end2end/test_invocations.py
+++ b/tests/end2end/test_invocations.py
@@ -70,6 +70,7 @@ def temp_basedir_env(tmpdir, short_tmpdir):
@pytest.mark.linux
+@pytest.mark.unicode_locale
def test_ascii_locale(request, server, tmpdir, quteproc_new):
"""Test downloads with LC_ALL=C set.
diff --git a/tests/unit/commands/test_userscripts.py b/tests/unit/commands/test_userscripts.py
index 9a6490aca..32f9a1bb9 100644
--- a/tests/unit/commands/test_userscripts.py
+++ b/tests/unit/commands/test_userscripts.py
@@ -241,9 +241,8 @@ def test_unicode_error(caplog, qtbot, py_proc, runner):
runner.store_html('')
assert len(caplog.records) == 1
- expected = ("Invalid unicode in userscript output: 'utf-8' codec can't "
- "decode byte 0x80 in position 0: invalid start byte")
- assert caplog.records[0].message == expected
+ expected = "Invalid unicode in userscript output: "
+ assert caplog.records[0].message.startswith(expected)
@pytest.mark.fake_os('unknown') Continuing that effort once this PR is in. |
@The-Compiler No I still get lots of errors. Here's a run-down of what I'm doing:
PyQt is 5.9 (self compiled) Running the tests on commit 4c2aeb0
The most common error I'm getting is
|
I've commented in #2777 about that issue. Can you please reply there? |
I haven't had time to look at why the testsuite is failing for you in that weird way yet, so I took over here to merge things - I hope you don't mind! 😉 The reason the (existing) tests were failing is because The new tests also needed some fixes to work properly - I added them in fdc4343. Thanks! |
Fixes qutebrowser/qutebrowser/#1450
This change is