Skip to content

Commit 490c842

Browse files
committed
Fix bug in sequential terminator logic
1 parent 5c1c427 commit 490c842

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cmd2/parsing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,16 @@ def parse(self, rawinput: str) -> Statement:
256256
if cur_token.startswith(test_terminator):
257257
terminator_pos = pos
258258
terminator = test_terminator
259+
# break the inner loop, and we want to break the
260+
# outer loop too
259261
break
262+
else:
263+
# this else clause is only run if the inner loop
264+
# didn't execute a break. If it didn't, then
265+
# continue to the next iteration of the outer loop
266+
continue
267+
# inner loop was broken, break the outer
268+
break
260269

261270
if terminator:
262271
if terminator == LINE_FEED:

tests/test_parsing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ def test_parse_redirect_inside_terminator(parser):
263263
def test_parse_multiple_terminators(parser, line, terminator):
264264
statement = parser.parse(line)
265265
assert statement.multiline_command == 'multiline'
266-
assert statement.args == 'has | inside'
267-
assert statement.argv == ['multiline', 'has', '|', 'inside']
266+
assert statement.args == 'with | inside'
267+
assert statement.argv == ['multiline', 'with', '|', 'inside']
268268
assert statement.terminator == terminator
269269

270270
def test_parse_unfinished_multiliine_command(parser):

0 commit comments

Comments
 (0)