summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-10-18 17:43:51 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-10-18 17:43:51 +0100
commitcfbef97efd124980a0716de43eabafc2fc7cb913 (patch)
tree3c3cef119bef0a12e55a2e5df706744e3d2205a5
parentf141523dd1056a9f79028d2e10db58cf04f2a2d6 (diff)
fix quoting in shlex
and catch ValueError on non-matching quotes. Explicit quoting in a commandprompt has been swallowed by shlex before.
-rw-r--r--alot/commands/__init__.py7
-rw-r--r--alot/commands/taglist.py2
2 files changed, 7 insertions, 2 deletions
diff --git a/alot/commands/__init__.py b/alot/commands/__init__.py
index 651b0130..d8f1248f 100644
--- a/alot/commands/__init__.py
+++ b/alot/commands/__init__.py
@@ -1,5 +1,6 @@
import os
import sys
+import re
import glob
import shlex
import logging
@@ -92,7 +93,11 @@ def commandfactory(cmdline, mode='global'):
# allow to shellescape without a space after '!'
if cmdline.startswith('!'):
cmdline = 'shellescape \'%s\'' % cmdline[1:]
- args = shlex.split(cmdline.encode('utf-8'))
+ cmdline = re.sub(r'"(.*)"', r'"\\"\1\\""', cmdline)
+ try:
+ args = shlex.split(cmdline.encode('utf-8'))
+ except ValueError, e:
+ raise CommandParseError(e.message)
args = map(lambda x: x.decode('utf-8'), args) # get unicode strings
logging.debug('ARGS: %s' % args)
cmdname = args[0]
diff --git a/alot/commands/taglist.py b/alot/commands/taglist.py
index 610dc2c1..8b896fc9 100644
--- a/alot/commands/taglist.py
+++ b/alot/commands/taglist.py
@@ -8,5 +8,5 @@ MODE = 'taglist'
class TaglistSelectCommand(Command):
def apply(self, ui):
tagstring = ui.current_buffer.get_selected_tag()
- cmd = SearchCommand(query=['tag:\"%s\"' % tagstring])
+ cmd = SearchCommand(query=['tag:"%s"' % tagstring])
ui.apply_command(cmd)