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
have to parse the exception string...
"""
try:
return shlex.split(s)
except ValueError as e:
if str(e) == "No closing quotation":
# e.g. eggs "bacon ham
# -> we fix this as eggs "bacon ham"
s += '"'
elif str(e) == "No escaped character":
# e.g. eggs\
# -> we fix this as eggs\\
s += '\\'
else:
raise
return shlex.split(s)
while True:
try:
return shlex.split(s)
except ValueError as e:
if str(e) == "No closing quotation":
# e.g. eggs "bacon ham
# -> we fix this as eggs "bacon ham"
s += '"'
elif str(e) == "No escaped character":
# e.g. eggs\
# -> we fix this as eggs\\
s += '\\'
else:
raise
def shell_escape(s):