safe_shlex_split: Give up after 3 tries.
This commit is contained in:
parent
2e35685fe1
commit
6a86924e60
@ -113,9 +113,11 @@ def safe_shlex_split(s):
|
||||
"""
|
||||
if s is None:
|
||||
raise TypeError("Can't split None!")
|
||||
while True:
|
||||
tokens = None
|
||||
orig_s = s
|
||||
for i in range(3):
|
||||
try:
|
||||
return shlex.split(s)
|
||||
tokens = shlex.split(s)
|
||||
except ValueError as e:
|
||||
if str(e) == "No closing quotation":
|
||||
# e.g. eggs "bacon ham
|
||||
@ -127,6 +129,11 @@ def safe_shlex_split(s):
|
||||
s += '\\'
|
||||
else:
|
||||
raise
|
||||
if tokens is None:
|
||||
raise AssertionError("Gave up splitting >{}< after {} tries. "
|
||||
"Attempted fixup: >{}<. This is a bug.".format(
|
||||
orig_s, i, s))
|
||||
return tokens
|
||||
|
||||
|
||||
def pastebin(text):
|
||||
|
Loading…
Reference in New Issue
Block a user