This is an automated email from the ASF dual-hosted git repository. sjanc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
commit 0803e16bbc561eda31dbe5fc3c8de650170ac820 Author: Szymon Janc <[email protected]> AuthorDate: Mon Oct 19 17:51:06 2026 +0200 newt/parse: Reject tokens after parenthesized expression Tokens following a parenthesized group were silently dropped, so "(A) B" evaluated as "A" and "!(A) B" as "!A". Report a parse error instead. Assisted-by: Claude:claude-opus-5-5 --- newt/parse/operators_test.go | 19 +++++++++++++++++++ newt/parse/parse.go | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/newt/parse/operators_test.go b/newt/parse/operators_test.go index a2c68179..125578ad 100644 --- a/newt/parse/operators_test.go +++ b/newt/parse/operators_test.go @@ -61,3 +61,22 @@ func TestOperatorsNoSpaces(t *testing.T) { } } } + +// Tokens following a parenthesized expression must be rejected. +func TestOperatorsTrailingTokens(t *testing.T) { + for _, expr := range []string{"(A) B", "!(A) B", "(A) (B)", + "(A) B && X"} { + + if _, err := LexAndParse(expr); err == nil { + t.Errorf("%s: parsed without error", expr) + } + } + + for _, expr := range []string{"(A)", "!(A)", "((A))", "(A) && (B)", + "!(A) || B"} { + + if _, err := LexAndParse(expr); err != nil { + t.Errorf("%s: unexpected error: %s", expr, err) + } + } +} diff --git a/newt/parse/parse.go b/newt/parse/parse.go index 4dc958f6..1d474ec3 100644 --- a/newt/parse/parse.go +++ b/newt/parse/parse.go @@ -300,6 +300,10 @@ func Parse(tokens []Token) (*Node, error) { if err != nil { return nil, err } + if len(stripped)+2 < len(tokens) { + return nil, fmt.Errorf("unexpected %s after parenthesis", + tokens[len(stripped)+2].Text) + } return Parse(stripped) }
