Fix safe_shlex_split when both conditions are true

This commit is contained in:
Florian Bruhin 2014-05-05 12:06:44 +02:00
parent c0ed2f52e6
commit ee1961cb42

View File

@ -64,20 +64,20 @@ def safe_shlex_split(s):
Since shlex raises ValueError in both cases we unfortunately Since shlex raises ValueError in both cases we unfortunately
have to parse the exception string... have to parse the exception string...
""" """
try: while True:
return shlex.split(s) try:
except ValueError as e: return shlex.split(s)
if str(e) == "No closing quotation": except ValueError as e:
# e.g. eggs "bacon ham if str(e) == "No closing quotation":
# -> we fix this as eggs "bacon ham" # e.g. eggs "bacon ham
s += '"' # -> we fix this as eggs "bacon ham"
elif str(e) == "No escaped character": s += '"'
# e.g. eggs\ elif str(e) == "No escaped character":
# -> we fix this as eggs\\ # e.g. eggs\
s += '\\' # -> we fix this as eggs\\
else: s += '\\'
raise else:
return shlex.split(s) raise
def shell_escape(s): def shell_escape(s):