Kaydet (Commit) fd16fcaf authored tarafından Vinay Sajip's avatar Vinay Sajip

Issue #21999: Handled empty strings correctly when in POSIX mode.

üst e1f3afbd
...@@ -230,7 +230,7 @@ class shlex: ...@@ -230,7 +230,7 @@ class shlex:
if self.debug >= 2: if self.debug >= 2:
print "shlex: I see punctuation in word state" print "shlex: I see punctuation in word state"
self.state = ' ' self.state = ' '
if self.token: if self.token or (self.posix and quoted):
break # emit current token break # emit current token
else: else:
continue continue
......
...@@ -178,6 +178,19 @@ class ShlexTest(unittest.TestCase): ...@@ -178,6 +178,19 @@ class ShlexTest(unittest.TestCase):
"%s: %s != %s" % "%s: %s != %s" %
(self.data[i][0], l, self.data[i][1:])) (self.data[i][0], l, self.data[i][1:]))
def testEmptyStringHandling(self):
"""Test that parsing of empty strings is correctly handled."""
# see Issue #21999
expected = ['', ')', 'abc']
s = shlex.shlex("'')abc", posix=True)
slist = list(s)
self.assertEqual(slist, expected)
expected = ["''", ')', 'abc']
s = shlex.shlex("'')abc")
self.assertEqual(list(s), expected)
# Allow this test to be used with old shlex.py # Allow this test to be used with old shlex.py
if not getattr(shlex, "split", None): if not getattr(shlex, "split", None):
for methname in dir(ShlexTest): for methname in dir(ShlexTest):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment