From 16f7ce4a650482d62c290747492498567b76fb94 Mon Sep 17 00:00:00 2001 From: David Keijser Date: Mon, 9 Jan 2017 14:45:19 +0100 Subject: [PATCH] Don't quote simple strings that don't need it --- Makefile | 2 +- tests/event-manager/testonevent.py | 12 ++++++++++-- uzbl/plugins/cmd_expand.py | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 6dfc5aeed..f6d051fc1 100644 --- a/Makefile +++ b/Makefile @@ -163,7 +163,7 @@ test-uzbl-core-sandbox: sandbox uzbl-core sandbox-install-uzbl-core sandbox-inst rm -rf ./sandbox/usr test-uzbl-browser-sandbox: sandbox uzbl-browser sandbox-install-uzbl-browser sandbox-install-example-data - ./sandbox/env.sh ${PYTHON} -m uzbl.event_manager restart -navv & + ./sandbox/env.sh ${PYTHON} -m uzbl.event_manager restart -navvv & sleep 1 ./sandbox/env.sh uzbl-browser http://www.uzbl.org --verbose ./sandbox/env.sh ${PYTHON} -m uzbl.event_manager stop -vv -o /dev/null diff --git a/tests/event-manager/testonevent.py b/tests/event-manager/testonevent.py index 89a9855b2..741b8bfb7 100644 --- a/tests/event-manager/testonevent.py +++ b/tests/event-manager/testonevent.py @@ -15,15 +15,23 @@ def setUp(self): def test_command(self): oe = OnEventPlugin[self.uzbl] - event, command = 'FOO', "test 'test'" + event, command = 'FOO', 'test test' oe.parse_on_event('FOO test test') oe.event_handler('', on_event=event) self.uzbl.send.assert_called_once_with(command) + def test_command_with_quotes(self): + oe = OnEventPlugin[self.uzbl] + event, command = 'FOO', "test 'string with spaces'" + + oe.parse_on_event('FOO test "string with spaces"') + oe.event_handler('', on_event=event) + self.uzbl.send.assert_called_once_with(command) + def test_matching_pattern(self): oe = OnEventPlugin[self.uzbl] - event, command = 'FOO', "test 'test'" + event, command = 'FOO', "test test" oe.parse_on_event('FOO [ BAR ] test test') oe.event_handler('BAR else', on_event=event) diff --git a/uzbl/plugins/cmd_expand.py b/uzbl/plugins/cmd_expand.py index 35eefc3b0..742e4d757 100644 --- a/uzbl/plugins/cmd_expand.py +++ b/uzbl/plugins/cmd_expand.py @@ -1,3 +1,8 @@ +import re + +SIMPLE = re.compile('^[a-zA-Z]+$') + + def escape(str): for (level, char) in [(1, '\\'), (1, "'"), (1, '"'), (1, '@')]: str = str.replace(char, (level * '\\') + char) @@ -38,17 +43,23 @@ def cmd_expand(cmd, args): return cmd +def format_arg(a): + if SIMPLE.match(a): + return a + return repr(a) + + def send_user_command(uzbl, cmd, args): if cmd[0] == 'event': has_var = any('@' in x for x in cmd) event = cmd[1] - args = cmd_expand(' '.join(repr(c) for c in cmd[2:]), args) + args = cmd_expand(' '.join(format_arg(c) for c in cmd[2:]), args) if not has_var: # Bypass the roundtrip to uzbl and dispatch immediately uzbl.event(event, args) else: uzbl.send(' '.join(('event', event, args))) else: - cmd = ' '.join((cmd[0],) + tuple(repr(c) for c in cmd[1:])) + cmd = ' '.join((cmd[0],) + tuple(format_arg(c) for c in cmd[1:])) cmd = cmd_expand(cmd, args) uzbl.send(cmd)