Skip to content

Commit 7cdd8e4

Browse files
committed
parser: catch unbalanced closed paren in expr
1 parent 1b9d037 commit 7cdd8e4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/tclint/parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def parse(self, script, pos=None):
116116
lexer = Lexer(pos=pos)
117117
lexer.input(script)
118118
tree = self._parse_script(lexer, in_command_sub=False)
119+
assert (
120+
lexer.type() == TOK_EOF
121+
), "Didn't reach EOF parsing script, please file a bug report."
119122

120123
return tree
121124

@@ -565,6 +568,11 @@ def parse_expression(self, node):
565568
ts.input(node.contents)
566569

567570
contents = self._parse_expression(ts)
571+
ts.expect(
572+
TOK_EOF,
573+
message=f"expected end of expression, got {ts.value()}",
574+
pos=ts.pos(),
575+
)
568576
if isinstance(node, BracedWord):
569577
return BracedExpression(contents, pos=node.pos, end_pos=node.end_pos)
570578

tests/test_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,3 +779,10 @@ def bad_command_parser(*args):
779779
parser._commands = {"broken": bad_command_parser}
780780
with pytest.raises(RuntimeError):
781781
parser.parse("broken")
782+
783+
784+
def test_expr_unbalanced_close_paren():
785+
# Regression test for case where the error was ignored (and any content after the
786+
# close paren was silently dropped).
787+
with pytest.raises(TclSyntaxError):
788+
parse("expr {$foo )}")

0 commit comments

Comments
 (0)