diff --git a/Lib/shlex.py b/Lib/shlex.py index e87266f8dd..00f7da8f14 100644 --- a/Lib/shlex.py +++ b/Lib/shlex.py @@ -232,7 +232,7 @@ class shlex: break # emit current token else: continue - elif self.posix and nextchar in self.quotes: + elif self.posix and nextchar in self.quotes and self.state != 'c': self.state = nextchar elif self.posix and nextchar in self.escape: escapedstate = 'a' diff --git a/Lib/test/test_shlex.py b/Lib/test/test_shlex.py index 3936c97c8b..1e217ad72e 100644 --- a/Lib/test/test_shlex.py +++ b/Lib/test/test_shlex.py @@ -273,6 +273,10 @@ class ShlexTest(unittest.TestCase): # white space self.assertEqual(list(s), ['a', '&&', 'b', '||', 'c']) + def testPunctuationWithPosix(self): + s = shlex.shlex('<"a"', posix=True, punctuation_chars=True) + self.assertEqual(list(s), ['<', 'a']) + def testEmptyStringHandling(self): """Test that parsing of empty strings is correctly handled.""" # see Issue #21999