Repository navigation
Conversation
…rvive rewrite Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mgwedd
force-pushed
the
fix/hook-preserve-case-terminators
branch
from
July 25, 2026 03:56
829007e to
e81c098
Compare
Adversarial coverage for the atomic ;; / ;& / ;;& fix (rtk-ai#3197): - quoted and backslash-escaped semicolons never become operators - spaced `; ;` stays two separators; `;;;` splits greedy-left - UTF-8 before `;;` does not skew offset/segment math - split_for_permissions still surfaces case-arm bodies for checking - rewrite keeps quoted `;;` and find -exec \; byte-verbatim Verified end-to-end: issue repro plus an 18-snippet matrix through `rtk hook claude` with bash -n validation of every rewrite. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
|
Closing in favour of #4130, which makes the same lexer and rewrite change for #3197 and adds regression tests for case statements inside for, while, if and function blocks. Thanks for the careful analysis and the edge case matrix; review or extra cases are welcome on #4130, or reply here if your version covers something it misses. |
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
;;as two separate;operators, and the rejoin step printed each one back as"; ", so any command that mixed a rewritable command with a case statement got corrupted into a bash syntax error.;;,;&, and;;&are now lexed as single operator tokens, using the same lookahead pattern already used for&&/||, and the rejoin step writes back the token's original value instead of reconstructing it character by character.;;into; ;, breaking everycasestatement (bash syntax error) #3197.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testrtk <command>output inspectedRan the pre-commit gate locally. I also added a regression test,
test_rewrite_preserves_case_terminators. It covers the three terminators (;;,;&,;;&) in a case statement. I checked this test fails against the old lexer (reproduces the; ;corruption). It passes with the fix.test_rewrite_preserves_case_terminators; fix turns it green.quoted/escaped ;; (never operators), ; ; with space (stays two separators),
;;;(greedy-left;; + ;), UTF-8 adjacent to ;; (offset), ;& at start/end of string.Invalid-bash inputs remain invalid, but don't become worse.;;yields byte matching segment boundaries to the old two-;tokens insplit_for_permissions/split_on_operators, and case-arm bodies (e.g. a)rm -rf x;;)are still surfaced for permission checking.Possible follow-up
Not needed for this fix, but worth noting: the lexer handles multi-char operators with per-branch lookahead (
|peeks for||/|&,&for&&/&>, and now;for;;/;&/;;&). A table-driven longest-match over a single operator list might make future operators a one-line addition and keep the rejoin spacing rules in one place. The issue also suggested splicing rewritten segments back by byte offset, leaving untouched bytes verbatim — that would get rid of this whole class of rejoin bugs.