mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Fixed #29132: Updated shlex to work better with punctuation chars in POSIX mode.
Thanks to Evan_ for the report and patch.
This commit is contained in:
parent
2e1b6ea4b7
commit
61eda7260a
2 changed files with 13 additions and 5 deletions
10
Lib/shlex.py
10
Lib/shlex.py
|
|
@ -232,11 +232,6 @@ class shlex:
|
||||||
break # emit current token
|
break # emit current token
|
||||||
else:
|
else:
|
||||||
continue
|
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':
|
elif self.state == 'c':
|
||||||
if nextchar in self.punctuation_chars:
|
if nextchar in self.punctuation_chars:
|
||||||
self.token += nextchar
|
self.token += nextchar
|
||||||
|
|
@ -245,6 +240,11 @@ class shlex:
|
||||||
self._pushback_chars.append(nextchar)
|
self._pushback_chars.append(nextchar)
|
||||||
self.state = ' '
|
self.state = ' '
|
||||||
break
|
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
|
elif (nextchar in self.wordchars or nextchar in self.quotes
|
||||||
or self.whitespace_split):
|
or self.whitespace_split):
|
||||||
self.token += nextchar
|
self.token += nextchar
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,14 @@ class ShlexTest(unittest.TestCase):
|
||||||
# white space
|
# white space
|
||||||
self.assertEqual(list(s), ['a', '&&', 'b', '||', 'c'])
|
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):
|
def testEmptyStringHandling(self):
|
||||||
"""Test that parsing of empty strings is correctly handled."""
|
"""Test that parsing of empty strings is correctly handled."""
|
||||||
# see Issue #21999
|
# see Issue #21999
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue