diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index ef61f3c00..f2209f711 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -22,6 +22,7 @@ import io import sys import enum +import json import os.path import collections import functools @@ -762,7 +763,7 @@ def set_clipboard(data, selection=False): raise SelectionUnsupportedError if log_clipboard: what = 'primary selection' if selection else 'clipboard' - log.misc.debug("Setting fake {}: {!r}".format(what, data)) + log.misc.debug("Setting fake {}: {}".format(what, json.dumps(data))) else: mode = QClipboard.Selection if selection else QClipboard.Clipboard clipboard.setText(data, mode=mode) diff --git a/tests/integration/features/conftest.py b/tests/integration/features/conftest.py index eaeef1f22..9e14a2b08 100644 --- a/tests/integration/features/conftest.py +++ b/tests/integration/features/conftest.py @@ -400,13 +400,15 @@ def check_open_tabs(quteproc, tabs): def clipboard_contains(quteproc, httpbin, what, content): expected = content.replace('(port)', str(httpbin.port)) expected = expected.replace('\\n', '\n') - quteproc.wait_for(message='Setting fake {}: {!r}'.format(what, expected)) + quteproc.wait_for(message='Setting fake {}: {!r}'.format( + what, json.dumps(expected))) @bdd.then(bdd.parsers.parse('the clipboard should contain:\n{content}')) def clipboard_contains_multiline(quteproc, content): expected = textwrap.dedent(content) - quteproc.wait_for(message='Setting fake clipboard: {!r}'.format(expected)) + quteproc.wait_for(message='Setting fake clipboard: {}'.format( + json.dumps(expected))) @bdd.then("qutebrowser should quit") diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 23bd5b301..b38e1ca3b 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -953,15 +953,17 @@ class TestGetSetClipboard: with pytest.raises(utils.SelectionUnsupportedError): utils.set_clipboard('foo', selection=True) - @pytest.mark.parametrize('selection, what', [ - (True, 'primary selection'), - (False, 'clipboard'), + @pytest.mark.parametrize('selection, what, text, expected', [ + (True, 'primary selection', 'fake text', 'fake text'), + (False, 'clipboard', 'fake text', 'fake text'), + (False, 'clipboard', 'füb', r'f\u00fcb'), ]) - def test_set_logging(self, clipboard_mock, caplog, selection, what): + def test_set_logging(self, clipboard_mock, caplog, selection, what, + text, expected): utils.log_clipboard = True - utils.set_clipboard('fake clipboard text', selection=selection) + utils.set_clipboard(text, selection=selection) assert not clipboard_mock.setText.called - expected = "Setting fake {}: 'fake clipboard text'".format(what) + expected = 'Setting fake {}: "{}"'.format(what, expected) assert caplog.records[0].message == expected def test_get(self):