Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/shlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def push_source(self, newstream, newfile=None):
self.infile = newfile
self.instream = newstream
self.lineno = 1
self.state = ' '
if self.debug:
if newfile is not None:
print('shlex: pushing to file %s' % (self.infile,))
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_shlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ def testCompat(self):
"%s: %s != %s" %
(self.data[i][0], l, self.data[i][1:]))

def test_push_source_after_eof(self):
for posix in (False, True):
with self.subTest(posix=posix):
lexer = shlex.shlex('a', posix=posix)
self.assertEqual(lexer.get_token(), 'a')
self.assertEqual(lexer.get_token(), lexer.eof)
lexer.push_source('b')
self.assertEqual(lexer.get_token(), 'b')
self.assertEqual(lexer.get_token(), lexer.eof)

def testSyntaxSplitAmpersandAndPipe(self):
"""Test handling of syntax splitting of &, |"""
# Could take these forms: &&, &, |&, ;&, ;;&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :meth:`shlex.shlex.push_source` so a new source pushed after EOF is read
correctly instead of being skipped.
Loading