summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2017-01-15 10:07:56 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2017-01-15 10:07:56 (GMT)
commitfc4b438163d7cfe5f0abe17dc78a496ca34fa593 (patch)
treec1d1bd120c7995592103c788cd47d661ef0f83fe
parentf25dec904c5e35ffd1e0c462edd6d360ebb313cd (diff)
parent61eda7260ac9fcdb6c5f066eb48dc344544bdfa6 (diff)
downloadcpython-fc4b438163d7cfe5f0abe17dc78a496ca34fa593.zip
cpython-fc4b438163d7cfe5f0abe17dc78a496ca34fa593.tar.gz
cpython-fc4b438163d7cfe5f0abe17dc78a496ca34fa593.tar.bz2
Closes #29132: Merged fix from 3.6.
-rw-r--r--Lib/shlex.py10
-rw-r--r--Lib/test/test_shlex.py8
2 files changed, 13 insertions, 5 deletions
diff --git a/Lib/shlex.py b/Lib/shlex.py
index e87266f..2c9786c 100644
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -232,11 +232,6 @@ class shlex:
break # emit current token
else:
continue
- elif self.posix and nextchar in self.quotes:
- self.state = nextchar
- elif self.posix and nextchar in self.escape:
- escapedstate = 'a'
- self.state = nextchar
elif self.state == 'c':
if nextchar in self.punctuation_chars:
self.token += nextchar
@@ -245,6 +240,11 @@ class shlex:
self._pushback_chars.append(nextchar)
self.state = ' '
break
+ elif self.posix and nextchar in self.quotes:
+ self.state = nextchar
+ elif self.posix and nextchar in self.escape:
+ escapedstate = 'a'
+ self.state = nextchar
elif (nextchar in self.wordchars or nextchar in self.quotes
or self.whitespace_split):
self.token += nextchar
diff --git a/Lib/test/test_shlex.py b/Lib/test/test_shlex.py
index 3936c97..fd35788 100644
--- a/Lib/test/test_shlex.py
+++ b/Lib/test/test_shlex.py
@@ -273,6 +273,14 @@ class ShlexTest(unittest.TestCase):
# white space
self.assertEqual(list(s), ['a', '&&', 'b', '||', 'c'])
+ def testPunctuationWithPosix(self):
+ """Test that punctuation_chars and posix behave correctly together."""
+ # see Issue #29132
+ s = shlex.shlex('f >"abc"', posix=True, punctuation_chars=True)
+ self.assertEqual(list(s), ['f', '>', 'abc'])
+ s = shlex.shlex('f >\\"abc\\"', posix=True, punctuation_chars=True)
+ self.assertEqual(list(s), ['f', '>', '"abc"'])
+
def testEmptyStringHandling(self):
"""Test that parsing of empty strings is correctly handled."""
# see Issue #21999