Repository navigation
fix: reject unconsumed trailing input in query parser (#305) - #351
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parse_ednreturned as soon as it parsed one complete top-level value, without checking whether tokens remained, so[1 2 3] garbage ) ] } 12345silently parsed as[1 2 3]with the trailing content dropped — no error raised.parse_queryandparse_ruleonly ever readelements[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 5instead of rejecting it as malformed (the correct place for:max-resultsis inside the vector). This is the same defectparse_transact/parse_retractalready closed in :valid-at appears to filter by transaction time instead of a fact's actual valid-from date #303.transact/retractalready use.Fixes #305.
Test plan
src/query/datalog/parser.rs, TDD'd (confirmed RED before GREEN), asserting on specific error-message content per code reviewcargo test --lib query::datalog::parser::tests— 107/107 passcargo test— all 37 binaries, 0 failurescargo clippy --libclean,cargo fmt --checkcleanCo-Authored-By: Claude Sonnet 5 noreply@anthropic.com
https://claude.ai/code/session_01Nsh3ZnmoK6PTaUbp4HcqHY