Fix safe_shlex_split when both conditions are true
This commit is contained in:
parent
c0ed2f52e6
commit
ee1961cb42
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user