Repository navigation
fix: preserve quoted command substitution newlines - #7
Merged
Merged
Conversation
caomengxuan666
added a commit
that referenced
this pull request
Sep 26, 2026
…sh#144) After a \' escaped quote the GNU lexer re-enters single-quote state: parse.y:5366-5398 read_token_word consumes the escape pair without opening quote state (pass_next_character covers exactly one char, parse.y:5358-5362), so the next ' opens a fresh parse_matched_pair span (parse.y:5419-5437). Inside that span every byte is quoted data -- subst.c:11882-11886 expand_word_internal case '\'' hands the whole span to add_quoted_string without consulting the comsub scanner, and dequote_string (subst.c:4807) later removes only the delimiters. Rubash's tokenizer (skip_word_inner, has_unclosed_quotes, has_unclosed_command_substitution) already modeled this correctly; the divergence was in assignment-word quote removal, which stripped the '...' delimiters but left expansion triggers bare, so the assignment expander (expand_backtick_substitution_typed / expand_mixed_command_substitution_assignment via scan_substitution_spans) executed them: x='a'\''`b`' ran `b` (rc=127, value truncated to a'); a lone backtick (c03/c04) died as a fatal EOF. This killed bash-completion at bash_completion:188 and ssh.bash:457 on load. Fix, by the protect_fully_single_quoted_assignment convention (classification.rs) and f8b6328's word-wide protection: - quotes.rs remove_shell_quotes_outside_backticks: content of '...' spans now travels as data carriers ($ -> \x1f, ` -> \x1a, " -> \x18), matching how fully-single-quoted RHSes already travel. - quotes.rs new remove_shell_quotes_assignment (word.rs $(-branch): same carrier protection for assignment words mixing spans with a live $(...) (`x='a'\''`b`'$(echo z)` keeps `b` literal). - The word path deliberately stays unprotected: plain `echo 'a`b'` prints through paths that do not decode \x1a (probed: leaks \x032). - assignment_expansion.rs: drop the `\'`->`'` collapse in the quoted restore block. Source \' already arrives as the bare \x17 carrier; a literal \ in front of it is data from the end of a single-quoted span (bash_completion:188 `'^([^\''` stores `^([^\` with the backslash; the collapse ate it). Unblocked: `source bash_completion` rc=0, complete -p = 130 = GNU's 131 env-free entries minus the known complete -D gap (rubash#133); ssh.bash loads rc=0; 452-file isolation matrix 451 OK vs GNU 452 (sole fail = tar.bash regex `{n,m}` quantifier, pre-existing bucket #7). probes/mini c01-c05 match GNU byte-for-byte; 36-case class matrix 32 pass (all 5 remaining divergences pre-exist on the base build and live in word-position consumers -- case patterns, here-strings, pipeline word decode -- tracked for the WORD_DESC quote-flags port). Verified: cargo build 0 warnings, cargo test --lib 446 green, cargo check --tests for x86_64-unknown-linux-gnu and aarch64-apple-darwin clean, rustfmt clean. src/lexer/continuation.rs NOT touched (its \' tracking was already correct).
This was referenced Oct 25, 2026
This was referenced Nov 6, 2026
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.
Fixes command substitution field splitting so raw word metadata is used to detect whether
$()/backtick substitution was unquoted. This preserves internal newlines for quoted command substitution while keeping unquoted field splitting behavior.Tests: