Merge branch 'fiete201-unicode-error'

This commit is contained in:
Florian Bruhin 2016-12-28 23:04:27 +01:00
commit 36bb8f5f5a
3 changed files with 29 additions and 4 deletions

View File

@ -191,6 +191,7 @@ Contributors, sorted by the number of commits in descending order:
* Michael Hoang
* Liam BEGUIN
* Julie Engel
* Fritz Reichwald
* skinnay
* Zach-Button
* Tomasz Kramkowski
@ -199,7 +200,6 @@ Contributors, sorted by the number of commits in descending order:
* Nikolay Amiantov
* Ismail S
* Halfwit
* Fritz Reichwald
* David Vogt
* Claire Cavanaugh
* rikn00

View File

@ -65,9 +65,13 @@ class _QtFIFOReader(QObject):
"""(Try to) read a line from the FIFO."""
log.procs.debug("QSocketNotifier triggered!")
self._notifier.setEnabled(False)
for line in self._fifo:
self.got_line.emit(line.rstrip('\r\n'))
self._notifier.setEnabled(True)
try:
for line in self._fifo:
self.got_line.emit(line.rstrip('\r\n'))
self._notifier.setEnabled(True)
except UnicodeDecodeError as e:
log.misc.error("Invalid unicode in userscript output: {}"
.format(e))
def cleanup(self):
"""Clean up so the FIFO can be closed."""
@ -289,6 +293,9 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
self.got_cmd.emit(line.rstrip())
except OSError:
log.procs.exception("Failed to read command file!")
except UnicodeDecodeError as e:
log.misc.error("Invalid unicode in userscript output: {}"
.format(e))
super()._cleanup()
self.finished.emit()

View File

@ -227,6 +227,24 @@ def test_temporary_files_failed_cleanup(caplog, qtbot, py_proc, runner):
assert caplog.records[0].message.startswith(expected)
def test_unicode_error(caplog, qtbot, py_proc, runner):
cmd, args = py_proc(r"""
import os
with open(os.environ['QUTE_FIFO'], 'wb') as f:
f.write(b'\x80')
""")
with caplog.at_level(logging.ERROR):
with qtbot.waitSignal(runner.finished, timeout=10000):
runner.prepare_run(cmd, *args)
runner.store_text('')
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
def test_unsupported(monkeypatch, tabbed_browser_stubs):
monkeypatch.setattr(userscripts.os, 'name', 'toaster')
with pytest.raises(userscripts.UnsupportedError) as excinfo: