Skip to content

fix(glob): extglob quoted literals match via the CTLESC arm (Refs #3050) - #3098

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3050-extglob-quoted-literal-ctlesc
Nov 9, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3050-extglob-quoted-literal-ctlesc

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

根因

extglob 组内引号段字面必 NOMATCH:extglob_match_literal_with_case(src/executor/conditional/pattern.rs)没有 CTLESC 逃逸臂,经 escaper 产出的 CTLESC 保护形落入 catch-all,被当作字面 CTLESC 字符比对。普通匹配器 case_pattern_atom_matches(同文件)已有该臂;extglob 字面匹配器缺失。

GNU 锚点

  • execute_cmd.c:3695-3729(execute_case_command):case pattern 先 expand_word_leave_quoted,再经 quote_string_for_globbing(..., QGLOB_CVTNULL|QGLOB_CTLESC),CTLESC 保护字符转为反斜杠逃逸;注释明言 "the strmatch() call must be able to recognize backslashes as escape characters"。
  • lib/glob/sm_loop.c:121-135(GMATCH case L('\\')):"backslash escape removes special meaning"——逃逸字符按字面匹配。
  • rubash 的 CTLESC 移植里,CTLESC 承担 GNU 反斜杠的角色;故在 extglob 字面匹配器补与普通匹配器同构的 CTLESC 臂。

修复

仅 src/executor/conditional/pattern.rs:extglob_match_literal_with_case 增加 CTLESC 臂(p + 1 < len 时按字面匹配 pattern[p + 1]、前进两格;尾 CTLESC 落入原 catch-all 字面比对,与 case_pattern_atom_matches 同构)。

本 PR 删除了什么

无删除:纯加法修复(一个 match 臂)+ 回归钉 tests/issue3050_extglob_quoted_literal_regressions.rs(4 格)。无公开面变动,无死代码清理。

验证

  • 回归钉:base 4295c853 上 fail-first(5 格钉 0/5;[[ ]] 格另见残余);修复后 4/4 全绿。
  • UNVERIFIED-BY-CAPTAIN

残余(已另立单)

Refs #3050

Regression pins for rubash#3050: quoted metacharacters inside an
extglob group must match literally (GNU lib/glob/sm_loop.c:121-135,
backslash escape removes special meaning; execute_cmd.c:3695-3729,
quote_string_for_globbing with QGLOB_CTLESC). Fail-first on base
4295c85: 0 passed / 5 failed.
extglob_match_literal_with_case lacked the CTLESC escape arm the
ordinary matcher (case_pattern_atom_matches, same file) already has,
so a CTLESC-protected literal metacharacter inside an extglob group
fell into the catch-all and was compared as a literal CTLESC
character: @("a*b") never matched 'a*b'.

GNU anchors: execute_cmd.c:3695-3729 (quote_string_for_globbing with
QGLOB_CTLESC; strmatch must recognize backslash escapes) and
lib/glob/sm_loop.c:121-135 (GMATCH case L('\\'): backslash escape
removes special meaning). CTLESC is this port's spelling of that
escape; the arm added here is isomorphic to the ordinary matcher's
(trailing CTLESC falls through to the catch-all, as there).

The [[ == ]] pin cell is dropped from this PR: a quoted RHS routes
through quoted_conditional_pattern_status (conditional.rs) into
case_pattern_matches, never reaching the extglob matcher at all — a
separate routing gap in a collision-listed file, filed as #3100
(gated on the #3025 lane landing).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 9, 2026 00:55
@caomengxuan666
caomengxuan666 merged commit a432632 into master Nov 9, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 9, 2026
test: wave-2 pins W2d (Refs #3066, #3084, #3097)

第二波「钉先行」车道 W2d 的回归钉(基底 master `f17644d7`)。三单的修法面均被在飞 PR #2968 的文件表占住(declare/assign.rs、compound_exec.rs、temporary_assignments.rs),本 PR 只落钉 + 根因/修法设计(见车道 REPORT),门开后修法车道按钉施工。

Refs #3066 — declare 通道 locale 漏斗触发次数:`declare -a`/`declare -A` 转换既有标量、复合绑定、`local` 复合绑定在 GNU 均双响(declare.def:1105 的 per-variable hack),rubash 只响一次。钉文件 `tests/issue3066_declare_conversion_locale_funnel.rs`(含 fresh/有效值/标量 declare 对照与链路读回)。

Refs #3084 — DQ 反斜杠 case 主词:`case "${v=a\ b}"` 主词在 GNU 保留反斜杠(nomatch),rubash 丢失(match)。钉文件 `tests/issue3084_case_word_dq_backslash.rs`。

Refs #3097 — locale 漏斗三残余:元素赋值与 for/标量覆数组绑定不喂漏斗(存储臂早退跳过 note);declare 通道漏斗投影判据(attr_of)与标量读路径(标记集)不同源,警告命名原始存储形。钉文件 `tests/issue3097_locale_funnel_array_channels.rs`(含 #3080 移出的 3 格原文断言)。

队长复核:A0 纯钉审计、C 腿 GNU 5.3.20 抽查(20 探针全吻合)、D 卫生(rustfmt/marker-lint 均净)、E CI 10 success + 1 skipped 均已落;B 腿 fail-first 实测:基底 5 绿/17 红(#3066 2 绿/6 红、#3084 3 绿/3 红、#3097 0 绿/8 红),头树逐 fn 完全相同(详见复核记录)。

## 本 PR 删除了什么

无(纯测试新增)。净行数:+720 行(3 个新钉文件:`tests/issue3066_declare_conversion_locale_funnel.rs` +263、`tests/issue3084_case_word_dq_backslash.rs` +150、`tests/issue3097_locale_funnel_array_channels.rs` +307;删除 0 行)。

注意:master 已推进到 `a432632d`(#3098 合入),合入前须 update-branch。
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
…3190)

The extglob group-structure scanners (extglob_group_end and
extglob_split_alternatives in src/executor/conditional/extglob.rs) do
not honour the CTLESC escape, so a quoted structural character inside
an extglob group is read as pattern structure: a quoted '[' starts
the bracket skip and runs past the group end, a quoted '(' inflates
the depth, a quoted ')' ends the group early, and a quoted '|' splits
the alternative. The literal matchers already carry the CTLESC arm
(#3098 for the extglob one); the alternatives just never reach them
intact.

GNU: quote_string_for_globbing (pathexp.c:246-272) rewrites every
CTLESC-quoted glob char as a backslash escape, and every pattern
scanner checks the escape first (PATSCAN lib/glob/sm_loop.c:697-700;
GMATCH escape arm sm_loop.c:121 before the bracket arm at :327).

11 test functions, script-file harness as in the issue3050 pin:
RED cells for the group-end face, the alternative-split face, all
five group operators and the [[ == ]] face; LOCK cells for the
shapes #3098 fixed and for the accidentally-rescued shapes.
Expectations verified byte-for-byte against GNU bash 5.3.20.

Co-authored-by: 曹梦轩 <[email protected]>
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