Repository navigation
fix(lexer): word-level $(( cmd ) || cmd) ran the )) arithmetic scan at six sites, swallowing the enclosing word (rubash#2096) - #2099
Merged
Conversation
…t six sites, swallowing the enclosing word (rubash#2096)
GNU classifies a word-level $(( as arithmetic only when the second '('s
balanced group closes right before ')': parse.y:4464-4473 parse_comsub
hands the word to parse_matched_pair(P_ARITH), a plain nesting match
(parse.y:3898 count=1), and the balanced-group-then-require-')' verdict
lives only at command position (parse.y:4900 parse_dparen -> parse.y:4970
parse_arith_cmd). Inside double quotes the nested $( recursion
(parse.y:4183-4188) keeps the top-level ')' as quoted text.
The token-start site has gated on dollar_double_paren_is_arithmetic since
#512; skip_cmd_subst, skip_double, skip_braced (both arms), run_skip_brace
and skip_word_inner classified $(( unconditionally and skip_arith_paren's
))-pair hunt then consumed past the closing quote to EOF. nvm v0.40.3
reprints nvm.sh:1336 ALIAS_TEMP="$( ( ... ) || nvm_echo)" spaceless into
every respawned background child's -c source, so each nvm ls emitted six
'syntax error near unexpected token )'' lines and lost the default-alias
output; GNU emits none.
All six sites now share the same predicate; arithmetic-true forms keep the
unchanged skip_arith_paren path.
Formatting: applied rustfmt directly to the three touched files (cargo fmt
aborts on this Windows tree with OS error 206 - filename too long - the
documented hook precedent); commit made with --no-verify for that reason
only.
Verification: tests/issue2096_dollar_dparen_subshell_or_list_regressions.rs
8/8; 17-case GNU-diff battery stdout byte-identical; 83-suite
true-baseline ledger vs pristine 5edad05 identical except the coproc
GNU-side timing flake (8-line variant reproduced on the pristine binary);
nvm ls end-to-end 6 -> 0 syntax-error lines, alias lines restored, on the
psmux real-tty niu face rebuilt against this engine.
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 #2096.
Root cause
Word-level
$(( cmd ) || cmd)— a command substitution of a subshell-or-list — was classified as arithmetic at six lexer scan sites, andskip_arith_paren's))-pair hunt (no))exists in this construct) consumed past the enclosing quote to end of input: one-line top-level assignments were silently swallowed whole; inside a function body it surfaced assyntax error: unexpected end of file from '{'/`while'.Real-world face: nvm v0.40.3 (
nvm.sh:1336ALIAS_TEMP="$( ( ... ) || nvm_echo)") reprinted spaceless by the async respawn prelude — everynvm lsspawned 6 background children whose-csource failed to parse → exactly 6 lines ofniu: -c: line 103: syntax error near unexpected token `)'per invocation (GNU: 0) and the default-alias lines (iojs -> N/A (default)…) never printed.GNU specification (vendored bash.git @9c465866, Bash-5.3 patch 20)
parse.y:4451 parse_comsub(), 4464-4473: word-level$(peeking(hands the word toparse_matched_pair(qc,'(',')',P_ARITH)— a plain balanced nesting match (parse.y:3898 count = 1; 3998-4005 count++/count--). Never a))hunt at word level.)arithmetic verdict exists only at command position:parse.y:4900 parse_dparen()→parse.y:4970 parse_arith_cmd()(4970-4996).parse.y:4183-4188(insideparse_matched_pair): a dquoted$(recurses intoparse_comsub; the top-level)is quoted text and the closing"still delimits.Fix
Apply the existing
dollar_double_paren_is_arithmeticgate — the same predicate the token-start site has used since #512 — at the six sibling sites that classified$((unconditionally:src/lexer/skip.rs:skip_cmd_subst,skip_double,skip_braced(both arms),run_skip_bracesrc/lexer/word.rs:skip_word_innerThis converges the whole class onto one predicate (no new symptom checks); arithmetic-true forms keep the unchanged
skip_arith_parenpath.Evidence
tests/issue2096_dollar_dparen_subshell_or_list_regressions.rs: 8 pins (dquoted, function-body, mid-word,${}-default, nested-comsub, the serialized nvm shape, arith-true guard, EOF diagnostics).nvm lssyntax errors 6 → 0, exit 0, default-alias lines restored; psmux real-tty face with niu (product) rebuilt against this engine — 0 syntax-error lines, alias lines restored, prompt returns.origin/master(5edad05) — all 82 static suites byte-identical (1015 = 1015 diff lines); the single moving line,coproc4 -> 8, is a WSL GNU-side timing flake: the 8-linegnu.outvariant reproduces on the pristine binary too (alternating reruns: 4,4,4 on fixed/pristine/fixed, 8 on pristine), while the rubash-siderb.outis byte-identical across every run.