Skip to content

fix: reject unconsumed trailing input in query parser (#305) - #351

Merged
adityamukho merged 2 commits into
mainfrom
worktree-fix-query-parser-trailing-input-305
Aug 24, 2026
Merged

adityamukho merged 2 commits into
mainfrom
worktree-fix-query-parser-trailing-input-305

Conversation

@adityamukho

Copy link
Copy Markdown
Collaborator

Summary

  • parse_edn returned as soon as it parsed one complete top-level value, without checking whether tokens remained, so [1 2 3] garbage ) ] } 12345 silently parsed as [1 2 3] with the trailing content dropped — no error raised.
  • parse_query and parse_rule only ever read elements[0] and silently ignored any additional elements in the command's argument list, so (query [:find ...] :max-results 5) parsed as the query alone, discarding :max-results 5 instead of rejecting it as malformed (the correct place for :max-results is inside the vector). This is the same defect parse_transact/parse_retract already closed in :valid-at appears to filter by transaction time instead of a fact's actual valid-from date #303.
  • Both are now hard parse errors, matching the "unexpected trailing argument(s)" wording transact/retract already use.

Fixes #305.

Test plan

  • 4 new regression tests in src/query/datalog/parser.rs, TDD'd (confirmed RED before GREEN), asserting on specific error-message content per code review
  • cargo test --lib query::datalog::parser::tests — 107/107 pass
  • Full cargo test — all 37 binaries, 0 failures
  • cargo clippy --lib clean, cargo fmt --check clean
  • Independent code review (general-purpose subagent): no Critical/Important issues remaining after addressing the one Important finding (strengthen test assertions)
  • Verified no caller in this repo (parser.rs, repl.rs, tests, demos) relies on trailing-token tolerance

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY

adityamukho and others added 2 commits August 24, 2026 20:00
parse_edn returned as soon as it parsed one complete top-level value,
without checking whether tokens remained, so `[1 2 3] garbage ) ] }
12345` silently parsed as `[1 2 3]` with everything after it dropped —
no error, no indication anything was ignored. parse_edn now errors if
tokens remain once the top-level value is parsed.

Separately, parse_query and parse_rule accepted and silently ignored
any arguments after their vector, the same defect (transact ...) and
(retract ...) already closed for #303 — so `(query [:find ...]
:max-results 5)` parsed as the query alone, discarding the trailing
clause instead of rejecting the malformed call. Both now reject extra
trailing arguments with the same wording transact/retract already use.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY
Per code review: the 4 new trailing-input tests only checked is_err(),
which can't distinguish the intended rejection from an unrelated one.
Assert on the error message content instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit f90ea3e into main Aug 24, 2026
17 checks passed
@adityamukho
adityamukho deleted the worktree-fix-query-parser-trailing-input-305 branch August 24, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query parser silently discards trailing input after a complete form (garbage or documented clauses alike)

1 participant