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
|
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user