From 07fbf73deec6a6537390fdadf1f6a7e10522cb6b Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Tue, 21 Apr 2015 15:49:27 +0200 Subject: [PATCH] Fix for #322 --- docs/advanced.rst | 2 +- features/regression.feature | 2 +- features/steps/core.py | 25 ++++++++----------------- jrnl/util.py | 6 +++--- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/docs/advanced.rst b/docs/advanced.rst index 07611b1a..e28975fe 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -18,7 +18,7 @@ The configuration file is a simple JSON file with the following options and can - ``journals`` paths to your journal files - ``editor`` - if set, executes this command to launch an external editor for writing your entries, e.g. ``vim``. Some editors require special options to work properly, see :doc:`FAQ ` for details. This value can either be a string such as the earlier ``"editor": "vim"`` example or ``"editor": ["vim", "+set ft=markdown"]`` if you want to pass arguments to the editor. + if set, executes this command to launch an external editor for writing your entries, e.g. ``vim``. Some editors require special options to work properly, see :doc:`FAQ ` for details. - ``encrypt`` if ``true``, encrypts your journal using AES. - ``tagsymbols`` diff --git a/features/regression.feature b/features/regression.feature index 6013b804..102566b2 100644 --- a/features/regression.feature +++ b/features/regression.feature @@ -61,7 +61,7 @@ Feature: Zapped bugs should stay dead. Scenario: Title with an embedded period on DayOne journal Given we use the config "dayone.yaml" - When we run "jrnl 04-24-2014: Ran 6.2 miles today in 1:02:03. I'm feeling sore because I forgot to stretch." + When we run "jrnl 04-24-2014: "Ran 6.2 miles today in 1:02:03. I'm feeling sore because I forgot to stretch."" Then we should see the message "Entry added" When we run "jrnl -1" Then the output should be diff --git a/features/steps/core.py b/features/steps/core.py index ba5b3abe..d9e409ce 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -1,3 +1,6 @@ +from __future__ import unicode_literals +from __future__ import absolute_import + from behave import given, when, then from jrnl import cli, install, Journal, util from jrnl import __version__ @@ -12,23 +15,11 @@ try: except ImportError: from cStringIO import StringIO import tzlocal +import shlex -def _parse_args(command): - nargs = [] - concats = [] - for a in command.split()[1:]: - if a.startswith("'") and a.endswith("'"): - nargs.append(a.strip("'")) - elif a.startswith("'"): - concats.append(a.strip("'")) - elif a.endswith("'"): - concats.append(a.strip("'")) - nargs.append(u" ".join(concats)) - concats = [] - else: - nargs.append(a) - return nargs +def ushlex(command): + return map(lambda s: s.decode('UTF8'), shlex.split(command.encode('utf8'))) def read_journal(journal_name="default"): @@ -62,7 +53,7 @@ def set_config(context, config_file): @when('we run "{command}" and enter "{inputs}"') def run_with_input(context, command, inputs=None): text = inputs or context.text - args = _parse_args(command) + args = ushlex(command)[1:] buffer = StringIO(text.strip()) util.STDIN = buffer try: @@ -74,7 +65,7 @@ def run_with_input(context, command, inputs=None): @when('we run "{command}"') def run(context, command): - args = _parse_args(command) + args = ushlex(command)[1:] try: cli.run(args or None) context.exit_status = 0 diff --git a/jrnl/util.py b/jrnl/util.py index a9515b79..1fd99c24 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -12,6 +12,8 @@ import tempfile import subprocess import codecs import unicodedata +import shlex + PY3 = sys.version_info[0] == 3 PY2 = sys.version_info[0] == 2 @@ -121,9 +123,7 @@ def get_text_from_editor(config, template=""): with codecs.open(tmpfile, 'w', "utf-8") as f: if template: f.write(template) - editor = config['editor'] - args = editor if isinstance(editor, list) else editor.split() - subprocess.call(args + [tmpfile]) + subprocess.call(shlex.split(config['editor']) + [tmpfile]) with codecs.open(tmpfile, "r", "utf-8") as f: raw = f.read() os.close(filehandle)