summaryrefslogtreecommitdiffstats
path: root/formats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2015-12-01 15:57:35 +0100
committerJan Pokorný <jpokorny@redhat.com>2015-12-17 23:35:41 +0100
commit8e039db541e76c94605063ea886852817377ab66 (patch)
treeeebf7623ecebe83815679f3a06109b4efb3ef376 /formats
parentcdac0375595acf6b986ce14e31ef5d3fb3f3034b (diff)
downloadclufter-8e039db541e76c94605063ea886852817377ab66.tar.gz
clufter-8e039db541e76c94605063ea886852817377ab66.tar.xz
clufter-8e039db541e76c94605063ea886852817377ab66.zip
formats/command: _escape: be more smart about what & how
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'formats')
-rw-r--r--formats/command.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/formats/command.py b/formats/command.py
index 3c9f0f1..fff6353 100644
--- a/formats/command.py
+++ b/formats/command.py
@@ -30,15 +30,20 @@ class command(SimpleFormat):
# rule: last but one item in qs cannot be escaped inside enquotion
ret = []
for b in base:
- if ' ' in b or any(b.startswith(q) or b.endswith(q) for q in qs):
+ use_qs = qs
+ if any(b.startswith(q) or b.endswith(q) for q in use_qs) \
+ or (any(c in b for c in ' #$') and not b.startswith('<<')
+ and not any(b.startswith(s) for s in ("$(", "<("))):
+ if '$' in b:
+ use_qs = tuple(c for c in use_qs if c != "'")
use_q = ''
- for q in qs:
+ for q in use_qs:
if q not in b:
use_q = q
break
else:
- use_q = qs[-1]
- if use_q != qs[0]:
+ use_q = use_qs[-1]
+ if use_q != use_qs[0]:
b = b.replace(use_q, '\\' + use_q)
else:
raise RuntimeError('cannot quote the argument')