fix(rules): stop flag alternation from consuming placeholder as flag value#154
fix(rules): stop flag alternation from consuming placeholder as flag value#154
Conversation
`should_consume_as_value()` fell through to `_ => true` for `LexToken::Placeholder`, causing patterns like `find * -exec|-execdir <cmd> \;|+` to parse `<cmd>` as a flag value instead of an independent placeholder. This broke wrapper recursive evaluation for flag-alternation + placeholder patterns. Also fix `literal_matches` to unescape backslash-escaped pattern tokens (e.g. `\;` -> `;`) so they match the command tokenizer output, which resolves shell escapes before comparison.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses parsing inaccuracies in command patterns, specifically resolving two issues: the incorrect consumption of placeholder tokens as flag values after flag alternation, and the mishandling of backslash-escaped characters in pattern literals. By preventing placeholders from being treated as flag values and by correctly unescaping backslashes during pattern matching, the changes ensure more robust and accurate evaluation of command rules, particularly for complex Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the reported bug where placeholder tokens were incorrectly consumed as flag values after flag alternation. The changes in pattern_parser.rs correctly prevent this behavior, and the new unescape_backslashes function in pattern_matcher.rs ensures that backslash-escaped pattern literals are matched accurately. The addition of comprehensive unit and integration tests thoroughly validates these fixes, demonstrating adherence to the repository's testing style guide by using rstest with named cases and indoc! for multiline strings. Overall, the changes improve the robustness and correctness of pattern matching.
…e docs should_consume_as_value_strict became identical to should_consume_as_value after the Placeholder exclusion was added. Inline the single call site and remove the now-redundant function to avoid misleading future readers. Document backslash escape matching behavior and add find -exec wrapper example to the placeholders page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #154 +/- ##
==========================================
+ Coverage 89.75% 89.78% +0.02%
==========================================
Files 37 37
Lines 7128 7155 +27
==========================================
+ Hits 6398 6424 +26
- Misses 730 731 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When a pattern contained both `\` and `*` (e.g. `\*` for a literal asterisk), the `*` check took priority over backslash unescaping, causing `\*` to be treated as a glob wildcard instead of a literal `*`. Check for backslash escapes first, unescape them, then only use glob matching if unescaped `*` characters remain (i.e. ones that were not preceded by `\`).
glob_match_with_sentinel was a near-duplicate of glob_match, differing only in sentinel restoration. Inline the sentinel handling into glob_match itself (guarded by a has_sentinel check) and remove the separate function.
The find wrapper with <cmd> placeholder was only covered by integration tests. Add E2E tests that exercise the full binary path (config parsing -> command evaluation -> JSON output) to verify the fix works end-to-end. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…-placeholder # Conflicts: # tests/e2e/check_generic.rs
Why
find * -exec|-execdir|-ok|-okdir <cmd> \;|+parsed<cmd>as a flag value instead of an independent placeholdershould_consume_as_value()fell through to_ => trueforLexToken::PlaceholderWhat
\;to;) during matching so they correctly match command tokens