Skip to content

fix(executor): expand non-ASCII bracket members to UTF-8 byte escapes in C locale (Refs #3791) - #3822

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3791-regex-bracket-nonascii-clocale
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3791-regex-bracket-nonascii-clocale

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Root cause

In the C locale [[ =~ ]] rejected every bracket expression holding a non-ASCII character with invalid regular expression. GNU anchor: lib/sh/shmatch.c:79-86 — sh_regmatch() calls regcomp() with REG_EXTENDED only; in the C locale glibc reads pattern and subject as bytes, so a literal multibyte char inside a bracket is the set of its UTF-8 bytes ([é] = {0xC3, 0xA9}).

Rubash compiles [[ =~ ]] patterns in Executor::compile_conditional_regex_uncached (src/executor/conditional.rs), which in byte mode builds a regex::bytes::Regex with .unicode(false). The regex crate rejects every non-ASCII char inside a character class in that mode ("Unicode not allowed here"), so every bracket holding a non-ASCII literal or range failed to compile.

Fix

In byte mode only, after the POSIX bracket translation and the ERE quantifier rewrite, expand every non-ASCII char to its \xHH byte escapes (expand_non_ascii_to_byte_escapes). Ranges then resolve on bytes exactly as glibc resolves them; a backslash before a non-ASCII char is dropped (glibc reads \ + byte as the literal byte; the crate rejects \é). Single choke point: compile_conditional_regex_uncached is the only regex-compile site for all three =~ paths. No change in UTF-8 locales, no change to src/lexer/continuation.rs or docs/api-ledger.md, no trust/signing/load-time-check mechanism.

Regression nail

tests/issue3791_regex_bracket_nonascii_clocale_regressions.rs: C-locale case (15 assertions, incl. the issue seed 10 + GNU-verified extras) and a C.utf8 control. Fail-first on base: C-locale test FAILED as predicted (every non-ASCII-bracket case returned 2, controls passed). Post-fix: 2/2 tests pass on X299-2607 (Windows MSVC cargo 1.99.1).

Verification (X299-2607)

  • Nail: 2/2 pass; 8 regex-family guard stems all pass (issue1717, issue1491, issue1061_1242, issue322, issue1177, issue1290, issue2981, issue3100).
  • RUSTFLAGS="-D warnings" cargo check --locked --lib --bins: clean.
  • cargo test --locked --lib: 1368 passed / 1 failed / 4 ignored — identical to base; the single failure (api::consumer_tests::issue2084_session_end_restores_host_process_state) is pre-existing on base too.
  • rustfmt --check, marker lint, UTF-8 boundary hygiene: all clean.
  • GNU oracle (local bash 5.3.20): regression seed R131-B ALL PASS (10/10).

本 PR 删除了什么

Nothing. Pure addition: one byte-mode expansion helper + one regression test file. No code, test, or public API removed.

Residual (out of scope, documented in the nail file header)

A lone invalid byte as the SUBJECT ([[ $'\xc3' =~ [é] ]], GNU m1) still does not match — the subject reaches the byte-mode matcher as a U+E000 raw-byte marker pair, not the raw byte. That is the subject-side marker decoding face, adjacent to #3545; it needs its own fix + nails.

UNVERIFIED-BY-CAPTAIN

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3822 第1轮 — 建议:PASS
head: 507761a base(merge-base): 969230b 文件: 2 个 +156/-0
关联 issue: #3791(状态: open,我核过的时间: 2026-11-17 11:10 CST)

机制核查:

  • 修复面在 src/executor/conditional.rs Executor::compile_conditional_regex_uncached:byte_mode(LC_ALL=C / ASCII-compatible 单字节 locale)下把非 ASCII 字符展开为 \xHH UTF-8 字节转义,作用于 POSIX bracket 翻译与 ERE 重写之后、regex 构建之前。GNU 侧 sh_regmatch() 直接把用户 pattern 交给 regcomp(&regex, pattern, REG_EXTENDED|REG_ICASE?)(third_party/bash/lib/sh/shmatch.c:79-86),C locale 下 glibc regcomp 按字节匹配,[[ =~ ]] 不走 bash 自己的转义层——所以把非 ASCII 源字符翻成字节转义让 regex crate 的 bytes 模式对齐 glibc 字节语义是对的锚点。byte_mode 判定与 UTF-8 locale 控制腿(cond_regex_bracket_nonascii_utf8_control)双侧钉住,无 UTF-8 locale 误伤。
  • diff 通读:仅 conditional.rs + 新钉文件,无顺手改动、无桥接层、无白名单式症状守卫(机制是「字节模式下按字节表达」,不是按符号补丁)。
  • 相邻残差(不属本 PR,已在 PR 正文声明):UTF-8 locale 下 [é-ÿ] 类范围表达式,GNU 本地 WSL oracle 报 Invalid collation character(rc=2),rubash 接受——此为既有分歧面,与 [[ =~ ]] regex operand: carrier bytes (0x0c, 0x14..0x1f) from $'...' or after | never match #3545 的 raw-byte subject 解码相邻,建议留给后续 issue,不阻塞本 PR。

腿(逐项给数字与名字):

  • 钉自跑:tests/issue3791_regex_bracket_nonascii_clocale_regressions.rs 2/2 通过(cond_regex_bracket_nonascii_c_locale、cond_regex_bracket_nonascii_utf8_control,head 507761a,Windows 本机)
  • fail-first:base 969230b 上同 stem 1 passed / 1 failed,红名 = {cond_regex_bracket_nonascii_c_locale},与 PR 声称一致(C-locale 腿红、UTF-8 控制腿绿)
  • lib 双边:head cargo test --lib -j2 1368 passed / 1 failed / 4 ignored;失败名 = {api::consumer_tests::issue2084_session_end_restores_host_process_state}(已知基线 [api] 进程内 Session 改写宿主进程环境与信号处置,后代子进程继承(嵌入契约面待盘点裁定) #2084);base 同 1368/1/4 同名 → 差集 = ∅
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked 通过,0 警告
  • 卫生:cargo fmt --check(涉及文件)rc=0;scripts/check-marker-literals.py OK(118 registry consts, 268 allowlisted sites);scripts/check-utf8-boundary-hygiene.sh clean
  • CI(run 44002101813 对应 PR head 检查):census 红 38 stem vs 同期 master run 44002101833 红 37 stem;差集方向为 PR 多 issue2340_wait_job_retention_regressions、issue2771_posix_function_tempenv_conversion,master 多 issue371_assoc_assignment_transform——issue2771/issue371 均为已知 flake,issue2340(wait/job 保留面)与本 PR regex 编译面无交集,判为 flake;本 PR 新增 stem issue3791_regex_bracket_nonascii_clocale_regressions 在 census 中 PASS(8894/8897 两腿);goldens 红 = {issue_753::case_9_declare_indexed_operand_binds_nothing, upstream_suite_slice_snapshots} 与 master 完全一致 = 基线。其余 9 个 CI job 全绿。
  • GNU 对照:WSL /usr/local/bin/bash GNU Bash 5.3.20(1)-release(脚本文件 probes-y2/gnu-3791-probe.sh,对照 LC_ALL=C 与 LC_ALL=C.utf8 两路):C locale 下 bracket/neg/anchored/agrave/emoji/alpha/literal/dot/agrave-eacute/range-y/bslash/repeat/group/nocase 共 15 项断言 rubash 与 GNU 输出逐字节一致;C.utf8 控制路一致(含 [é-ÿ] 范围两侧同为 Invalid collation character 语义路径——见相邻残差注记,rubash 在该 UTF-8 分支的具体报错文案待队长 Linux oracle 复核,本地 WSL 已确认 GNU 侧报错)。

F 点:无

未跑/VOID 的腿:

  • UTF-8 locale [é-ÿ] 报错文案的 Linux 原生复核:本机为 Windows + WSL 仿真,已按规程标注待队长 Linux oracle 复核;不影响本 PR 判词(该分支不在本 PR diff 面内)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】更正(复核补充):
上一条报告「GNU 对照」段中「本地 WSL oracle 对 [é-ÿ] 报 Invalid collation character」系探针环境伪影——env -i 经 WSL interop 未把 LC_ALL=C 传给 Windows 侧 rubash.exe,且早期脚本未走 issue 种子同款 env -i 纪律。按 issue #3791 种子同法复测(env -i PATH=… LC_ALL=C,WSL /usr/local/bin/bash 5.3.20(1) vs Windows 直跑 LC_ALL=C rubash.exe):

  • GNU C locale:[é]→m1、[é-ÿ]→m1、[^é]→m1、^[é]$→m0、[à-ÿ]x→m0、^[😀]$→m0、[[:alpha:]]é→m0、字面 é→m1、^.$é→m0、\é→m1、[é]{2}→m1、nocasematch É=~[é]→m1 —— 与 PR 钉的 15 项断言逐一相同;
  • rubash head 507761a Windows LC_ALL=C:bracket=0 range=0 neg=0 anchored=1 agrave=1 emoji=1 alpha=1 literal=0 dot=1 agrave-eacute=0 range-y=0 bslash=0 repeat=0 group=0 nocase=0,stderr 空,rc=0 —— 全等;
  • 「UTF-8 locale [é-ÿ] 报错文案」疑点一并消解:干净 C locale 下 GNU 接受范围表达式(字节语义),不存在该分歧。

结论维持:建议 PASS,且 GNU 对照腿升级为全等(15/15 + 尾部 6/6)。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 03:41
@caomengxuan666
caomengxuan666 merged commit 62f5ae6 into master Nov 17, 2026
10 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-BATCH-SUMMARY】Y2 波 4 条 draft 审核完毕(2026-11-17)

PR 建议判词 结果 mergeCommit / 阻塞
#3822 C locale =~ 非 ASCII bracket PASS MERGED,issue #3791 已关 62f5ae6
#3821 alias 预扫描 comsub 注释/引号 PASS MERGED,issue #3813 已关 ce3de0f
#3817 字面 C0 字节 carrier 冲突 FAIL 未合并,issue #3816 保持 open 见 issuecomment-6937706101(census +10 stems 归因未清)
#3812 procsub brace-group body PASS MERGED,issue #3808 已关 fb2a97f

要点:

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