Skip to content

fix(executor): honor CTLESC and bracket opacity in extglob group scanners (Refs #3189) - #3682

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3189-extglob-ctlesc-scanners
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3189-extglob-ctlesc-scanners

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • rubash#3189: case 'a[b' in @("a[b")) never matched — a quoted structural char inside an extglob group was interpreted as pattern structure before the literal matcher saw the alternative.
  • Root cause: the two group-structure scans in src/executor/conditional/extglob.rs treated the CTLESC spelling of a quoted char as two ordinary chars. extglob_group_end had a \ skip arm but no CTLESC arm (quoted [ opened the bracket half-scan and ran past the group end; quoted (/) moved the paren depth). extglob_split_alternatives had no CTLESC arm and no bracket opacity (CTLESC | split the alternative; a | inside a bracket expression split too).
  • Fix: make both scans follow GNU PATSCAN (lib/glob/sm_loop.c:676-757) — escape arm now covers \ and CTLESC alike (sm_loop.c:698-700; chars arrive CTLESC-protected per parse.y:5694-5706 got_escaped_character, the case pattern glob-quoted per execute_cmd.c:3724 quote_string_for_globbing QGLOB_CTLESC), and a shared extglob_bracket_scan_end keeps bracket contents opaque to group structure (sm_loop.c:709-737, bfirst rule :731, PARSE_SUBBRACKET :383-394/717-722, bnest == 0 requirement for the | split :749-751).

Legs

  • Pin tests/issue3189_extglob_quoted_bracket_literal.rs: 11/11 green (was 5/11 on master — the 6 RED stems flip, every LOCK stem stays green).
  • WSL GNU bash 5.3.x script-file probe (20 shapes incl. new mechanism faces a[|]b, a[\]b], []x], [[:alpha:]], [.].] in groups): byte-identical.
  • Neighbor stems: 20 extglob/case/pattern files all pass or show the identical red set as master (issue1673/2647/3205 env-bound, issue332 live-pin — unchanged).
  • cargo test --lib: 1351 passed, red set = baseline {issue2084} only.
  • RUSTFLAGS="-D warnings" cargo build --locked --bin rubash: clean.

Test plan

  • Pin stem green
  • GNU byte-identical probe
  • Neighbor stems unchanged red set
  • lib baseline red set only

Generated with Devin

…ners (Refs #3189)

The two extglob group-structure scans in extglob.rs did not treat the
CTLESC spelling of a quoted character as one opaque unit, so a quoted
structural character inside a group was interpreted as pattern
structure before the literal matcher saw the alternative:

- extglob_group_end had a `\` skip arm but no CTLESC arm: a quoted `[`
  opened the bracket half-scan and ran past the group end, a quoted `(`
  inflated the paren depth, and a quoted `)` closed the group early, so
  `@("a[b")`/`@("a(b")`/`@("a)b")` never found their `)`.
- extglob_split_alternatives had no CTLESC arm and no bracket opacity:
  `CTLESC |` split the alternative (leaving a dangling CTLESC) and a `|`
  inside a bracket expression was treated as an alternative boundary.

Both scans now follow GNU PATSCAN (lib/glob/sm_loop.c:676-757): the
escape arm covers `\` and CTLESC alike (sm_loop.c:698-700 — quoted
characters reach the scan CTLESC-protected per parse.y:5694-5706
got_escaped_character, the case pattern being glob-quoted per
execute_cmd.c:3724 quote_string_for_globbing QGLOB_CTLESC), and the
shared extglob_bracket_scan_end keeps a bracket expression's contents —
parens and `|` included — opaque to group structure until its closing
`]` (sm_loop.c:709-737, with the bfirst first-member-`]` rule at :731
and PARSE_SUBBRACKET `[.`/`[:`/`[=` handling at :717-722/:383-394,
which also requires bnest == 0 for the `|` split at :749-751).

Pin tests/issue3189_extglob_quoted_bracket_literal.rs: 11/11 green
(was 5/11 on master; the 6 RED cells flip, no LOCK cell regresses).
20-shape WSL GNU bash 5.3.x script-file probe is byte-identical,
including the new mechanism faces (`a[|]b`, `a[\]b]`, `[]x]`,
`[[:alpha:]]`, `[.].]` inside groups).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit fc1b848 into master Nov 15, 2026
8 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
fix(executor): re-derive POSIX mode on POSIXLY_CORRECT bind (Refs #3661)

GNU `sv_strict_posix` (variables.c:5820, 6257-6266) fires on every bind/unbind
of POSIXLY_CORRECT, not only on `set -o posix`. rubash split the two
directions: `apply_posix_mode_transition` keeps the `set -o` path's variable
binding; new `sync_posix_mode_from_variable` only re-derives the mode and
never writes the variable. Hooks sit at every bind/unbind funnel.
Written-text keying (expr.c:352, printf.def:112-113): arithmetic-element and
printf-element spellings do NOT flip the mode; statement-element and
declare/local-element operands DO.

Refs #3661 (the #2902 §2 gate: modernish dies rc=128 in capability
detection because a runtime `POSIXLY_CORRECT=1` assignment never armed
posix mode). #3661 stays open until the captain hand-closes it on this
merge; the #2902 re-run is dispatchable after that.

## 本 PR 删除了什么

No product code or files are deleted. The fix commit is +194/−3 across 12
source files (the −3 is the refactored transition body in `options.rs`).
The nail-correction commit rewrites the expectations of 4 existing nail
cells and the file header's probe summary, per GNU-oracle evidence; no nail
cell was removed (one was added: `temp_prefix_special_builtin_persists`).

## Captain verification (merge round R4, head 5e816ac, base 35437c4)

- Pin `issue3661_posixly_correct_runtime_hook_regressions`: 21/21 green on
  the merged shape (fail-first banked at delivery: 17 red / 3 green on base;
  GNU oracle matrix 25/25 SAME; neighbors 20 stems / 55 cells banked).
- `RUSTFLAGS="-D warnings" cargo check --locked --lib --bins`: rc=0, zero
  warnings. `rustfmt --check` on all 13 changed .rs files: rc=0.
- Full lib bilateral banked at delivery: 1249/0/4 both sides, failure
  name-set diff empty.
- CI on the R4 head (run 43723537799, head == 5e816ac): 3 failing jobs
  (Rust tests, Rust tests (macOS), GNU regression goldens and canaries),
  each failing ONLY on the issue2875 baseline cell
  (`api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell`);
  niu-canary success. PASS comment 6894681605 stands.
- Intersection (merge-base 2e02e90..35437c4 vs the PR's 13 files): exactly
  the 3 captain-released files — command_prepare.rs (tip #3482, ~3,900
  lines apart), temporary_assignments.rs (tip #3683 @@ -827 vs PR @@ -1460,
  ~600 lines, different functions), variable_state.rs (tip #3667 pure
  insertions in different functions). Rebase clean, zero conflicts.
- Zero-intersection exception for the tip move after R4: the tip moved
  35437c4 -> fc1b848 (user merged #3682, Refs #3189) while R4's legs
  were banked; the increment touches exactly one file,
  `src/executor/conditional/extglob.rs`, which is not among the PR's 13
  files (programmatic intersection: 0). The merged tree is therefore the
  R4-verified shape plus #3682's file only; no update-branch re-verify
  round is required. #3682's own CI was captain-named baseline-only
  (run 43721665167).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant