[Python-checkins] cpython (2.7): Issue #21999: Handled empty strings correctly when in POSIX mode.

vinay.sajip python-checkins at python.org
Tue Aug 9 09:58:34 EDT 2016


https://hg.python.org/cpython/rev/cf04243e8d7d
changeset:   102578:cf04243e8d7d
branch:      2.7
parent:      102543:09475e6135d0
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Tue Aug 09 14:57:03 2016 +0100
summary:
  Issue #21999: Handled empty strings correctly when in POSIX mode.

files:
  Lib/shlex.py           |   2 +-
  Lib/test/test_shlex.py |  13 +++++++++++++
  2 files changed, 14 insertions(+), 1 deletions(-)


diff --git a/Lib/shlex.py b/Lib/shlex.py
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -230,7 +230,7 @@
                     if self.debug >= 2:
                         print "shlex: I see punctuation in word state"
                     self.state = ' '
-                    if self.token:
+                    if self.token or (self.posix and quoted):
                         break   # emit current token
                     else:
                         continue
diff --git a/Lib/test/test_shlex.py b/Lib/test/test_shlex.py
--- a/Lib/test/test_shlex.py
+++ b/Lib/test/test_shlex.py
@@ -178,6 +178,19 @@
                              "%s: %s != %s" %
                              (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
 if not getattr(shlex, "split", None):
     for methname in dir(ShlexTest):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list