Skip to content

[bug] [P0] Two $((...)) in one word separated by non-alnum material (: space . -) mis-slice into ONE merged expression #376

Closed

Description

@caomengxuan666

Found by captain spot-check during the wt23/hist274 recovery (probe files under target/pd4.sh / target/pd5.sh). Pre-existing at 2e6b0e9 (= the 1.2.1 release lineage) — byte-identical failure on pristine base and current master; NOT a regression from 2ad6c17/b5b78aab. Shipped in 1.2.1.

Reproducer (WSL GNU Bash 5.3.0 script-file oracle)

echo "$((1+1)):$((2+2))"      # GNU: 2:4   rubash: rc=1, no output

rubash stderr: pd4.sh: line 1: 1+1)):4: arithmetic syntax error in expression (error token is ")):4")

Evidence matrix (all GNU-verified; rubash output vs GNU)

input rubash GNU
echo "$((1+1)):$((2+2))" ERROR 1+1)):4, empty stdout 2:4
echo $((1+1)):$((2+2)) (unquoted) ERROR 1+1)):4 2:4
echo "$((1+1)) $((2+2))" (space) ERROR 1+1)) 4 2 4
echo "$((1+1)).$((2+2))" ERROR 1+1)).4 2.4
echo "$((1+1))-$((2+2))" ERROR 1+1))-4 2-4
echo "$((1+1)):$((2+2)):$((3+3))" (triple) ERROR 1+1)):4:6 2:4:6
v=9; echo "$((v)):$((v))" (vars) ERROR v)):9 9:9
echo "$((1+1)):$PATH" (param 2nd) OK ok
echo "$PATH:$((1+1))" (param 1st) OK ok
echo "a$((1+1))b$((2+2))c" (alnum-adjacent) OK a2b4c same
single "$((expr))" any shape OK ok

Class boundary and mechanism evidence

Fires when a word contains two or more $((...)) separated only by non-alnum material (: space . -); alnum-adjacent material or a $param on either side avoids it. The error text pattern is diagnostic: first-raw-body + "))" + separator + <EXPANDED VALUES of the later comsubs> — e.g. triple colon gives 1+1)):4:6. That means the FIRST comsub's body slice greedily extends to the LAST )) of the word, the swallowed later $((...)) spans are then expanded (their values appear in the error), and the merged text fails the arithmetic parse. A span-matcher admission/anchoring bug in the word-level $(( scanner — the rubash#117 fast-path family shape.

GNU spec pointer for the fix lane

parse.y:5305 read_token_word() — on $(( the walker delegates to the arithmetic-command branch and the matched-pair machinery (parse.y:3877 parse_matched_pair()); each subsequent $(( is its own word event. Fix must make our span slicing anchor per-$(( (innermost/closest-first) instead of word-greedy. No whack-a-mole: if this lives on a text-layer fast path, converge it to the real scanner per AGENTS.md.

Upstream arith.tests has no )):$(( shape (verified by grep) — corpus blind spot; our gnusweep probes also missed it. Suggest adding the 11-shape matrix above as a regression fixture (tests/regression/fixtures or a new issueNNN suite) together with the fix.

Activity

  1. caomengxuan666 commented on Oct 1, 2026

    @caomengxuan666
    MemberAuthor

    Landed as d1cdb7b (cherry-picked from wt24/adjcomsub lane commit d8fa09be): new whole_word_arithmetic_substitution_body real span scanner (paren depth from 2, quotes/escapes opaque, admits only when the first balanced )) is the word's final characters) replacing the naive strip_prefix/strip_suffix admissions at parameter_core/expand_word/command_prepare. GNU spec: parse.y:3877 parse_matched_pair closes at the FIRST balanced )) (parse.y:3988), each later $(( is an independent word event (parse.y:5521). 14-test regression suite + 3 scanner unit tests; 11-shape matrix and expanded class boundary byte-identical to WSL GNU 5.3.0; carrier-domain (#354 family) and true-baseline slices unchanged. CI green on d1cdb7b. Incidental pre-existing gap ($'\n' between comsubs folded to space) filed separately.

  2. added 2 commits that reference this issue on Oct 1, 2026
  3. added
    bug
    P0-critical
    area:parser
    family:S1
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0-criticalarea:parserbugfamily:S1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions