Repository navigation
fix(executor): bracket carrier bytes match in ${v//[...]/r} (Refs #3546) - #3920
Merged
Merged
Conversation
Three pins: full 7-byte x 3-spelling matrix, two-carrier bracket, anchored/?/range/single/no-match/plain guards. Expected values are GNU bash 5.3.20 output from issue #3546, re-checked against local GNU bash 5.2.21 (all rows a_b, m_n_o, ? form ___).
…ders (Refs #3546) Root cause: the three ${v//...}/${v#...}/${v%...} finders prune candidates with pattern_match_length_bound (pattern atoms) but walked value CHAR boundaries. A carrier byte is stored as a two-char raw-byte marker pair (U+E000 + payload), so a single-atom bracket pattern (bound 1) pruned the only matching candidate (two-char pair slice) before the matcher ever saw it. The fix walks match-unit boundaries only, excluding marker_pair_split_points (same exclusion the #/$ removal walks already have, rubash#1261), and rewords the bound invariant from chars to match units. The matcher itself is untouched: byte-spelling flatten already folds pairs to one byte-char. GNU anchor: subst.c:9184 pat_subst() -> lib/glob/sm_loop.c:398 BRACKMATCH() compares bracket members against the candidate byte; carrier bytes are data. UNVERIFIED-BY-CAPTAIN: verification legs are PENDING — the new-server build route is down (egress proxy closes ssh during banner exchange, 6 attempts) and no other build slot is usable this round. Nail expectations are backed by local GNU bash 5.2.21 runs.
caomengxuan666
marked this pull request as ready for review
November 18, 2026 15:56
This was referenced Nov 18, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
## 根因
{var}<< heredoc 须在列表位置绑定(GNU redir.c:237 有序遍历);修法本体在原提交 307782b(pipeline_exec / execution_misc / redirections 等 8 文件),队长待改复核时仅剩一格钉红。
## 续作(本轮唯一改动)
`unterminated_varassign_heredoc_still_warns` 钉期望错、产品对:未终结 heredoc 吞掉文件剩余全部内容作体,后续 `echo "v=$v"` 行本身不存在于命令流中,stdout 应为空(GNU 5.3.20 oracle 实测:stdout 空、stderr 警告、rc 0;锚点 redir.c:963-968 / :1470 / :423)。只改钉(test-only +12/-1:stdout 断言 "v=\n"→"",保留 stderr 警告与 rc==0 断言,附 oracle 证据注释),产品代码未动。原钉系从已终结变体复制期望。
## 队长复核(2026-11-19 00:3x)
头 CI 逐名裁定(新头 da03356,run 44344314375):census 77,自带钉 12/12 绿,零新增 vs #3920/#3916 头(78;少 1 格为 issue1902 抖动格);goldens 基线二名(232 passed);issue1903 本轮 ok 未复现(时序抖动);CLI 仅 coproc 抖动格;Rust tests 绿,macOS job cancelled 且 steps 为空(从未运行,非产品红);darwin cross-target 同为 cancelled 且 steps 为空(从未运行,非产品红);ledger、交叉编译 linux/android、shell 功能、Windows 编译、niu-build 全绿。分支基底即现尖 47a24b2,无需 update-branch。
说明:本钉为行为锁定钉(产品在修前已合 GNU 值),非 fail-first 守卫钉;fail-first 不适用于本次 test-only 对齐。服务器腿(钉 stem 服务器复跑、lib 对齐、-D warnings、全量 rustfmt)因链路中断未跑,待恢复后补跑;产品面无改动,lib 不可能因此移动,census 即其证据。
Refs #3894。
本 PR 删除了什么:
未删除任何文件、函数、公开面或测试。产品修法见原提交;续作仅修改一处测试期望值。
This was referenced Nov 18, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
…ry faces (Refs #3921) Item 1 — zero-length-match advance: replace_parameter_pattern_inner copied one char past a zero-length match (GNU pat_subst:9286-9304 copies one CHARACTER, and in GNU one carrier byte / one U+E000 char is one character). A raw-byte marker pair (U+E000 + payload) or a literal-char escape pair (U+E400 + char) is one match unit, so the advance now lands on the next unit boundary from the #3920 finder table instead of stranding the cursor inside the pair. Item 2 — literal U+E000 user data, two faces, both oracle-verified against GNU bash 5.3.20 (LC_ALL=C.UTF-8): (a) `printf -v` stored the formatted output raw: the lone U+E000 + payload was read as a raw-byte marker pair at the first decode boundary, so `printf -v v '\uE000\uE001'` stored one NUL byte (len 1, plain expansion NUL, child-env spawn failure). The output is now value-entry encoded (entry_encode_value_text, the bytes_to_shell_text parity every other value channel uses) at the last step before storage, in all four assign_printf_output arms (scalar, indexed, assoc, nameref). (b) `declare -p` double-decoded: decode_to_visible_text folds E400 pairs to lone U+E000s, and the byte-view quoters (strtrans.c ansic_quote port, setattr.def:528-531) re-folded a lone U+E000 + payload-range char into a byte, so `declare -p` showed `$'\000'` for a correctly stored U+E000 U+E001. The display quoters (quote_declare_value, quote_array_element_value, quote_declare_display_value, quote_assoc_display_key, quote_listing_value) now re-spell the visible text as transport text before quoting, so the exactly-once decode yields the visible chars. The genuine-pair arm is unchanged (rubash#540/#1060). Pins: the two item-1 cells were already fail-first red; ten new item-2 cells (printf -v storage + declare -p display) are red on the unfixed base and green with this fix.
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
…#3252) Without `set -u`, `(( b[$undef]++ ))` was silent on stderr: the `$undef` inside the subscript expands to empty and the evaluation read/bound element 0. GNU bash 5.3 reports `b[]: bad array subscript` twice plus `((: \`b[]': not a valid identifier`, and keeps evaluating (rc 1). Root cause: `eval_subscript_index` (value.rs) mapped every empty expansion to index 0. GNU's law branches on the ENTRY, not the expansion: `(( ))`, `$(( ))` and `[[ ]]` run expand_arith_string before evalexp, so the STR token reaching evalexp is literally `b[]` and array_variable_name fails it (arrayfunc.c:1405-1416, `ni <= ind+1`); `let` operands arrive EXP_EXPANDED, so the token is `b[$undef]` and the empty expansion inside array_expand_index is index 0 (`let 'b[$undef]++'` binds b[0] silently — verified GNU 5.3.20). Fix: thread an `expanded_entry` flag from the evaluation entries into `ConditionalArithParser` (mod.rs / conditional.rs) and return `SubscriptIndex::Empty` from `eval_subscript_index` when a marker-decoded subscript is empty in an expand entry. Callers convert it to the existing `InvalidElement` shape: reads diagnose `b[]: bad array subscript` twice and yield 0; binds fail as `` `b[]': not a valid identifier `` and store nothing. Plain `=` never reads (expr.c:1395-1401), so it reports only the invalid identifier. Whitespace-only expansions stay index 0 in every entry (the bracket text is non-empty). Nested frames (variable-value recursion, subscript evalexp) run with the flag off: their input text reaches subexpr verbatim (expr.c:1241). GNU anchors: arrayfunc.c:1405-1416 array_variable_name, error.c:440-443 err_badarraysub, expr.c:1183/1227 expr_streval (two lookup points), expr.c:1395-1401 (EQ peektok), expr.c:331-354 expr_bind_variable -> sh_invalidid, expr.c:1044-1054/1101 exp0 post-inc/dec, expr.c:611-614 expassign (lind == -1). Regression nail: tests/issue3252_arith_subscript_diag_no_nounset.rs (19 cells: (( ))/let/$(( ))/[[ ]] forms, assign/++/--/pre-inc, bound/spaced/value-recursion/assoc controls). ## 队长续作(c5c0958c):assoc 空括号臂 续作车道以 GNU 5.3.20 oracle 证明钉是对的、产品是错的:`declare -A C; (( C[$undef]++ ))` 下 GNU 为 badsub ×2 + `` `C[]': not a valid identifier `` ×1(rc 1),产品只出 badsub ×2 且静默绑了 `C[""]`。根因在 src/executor/arithmetic/lvalue.rs:`parse_assoc_subscript` 的空括号分支 急于记 2× BadSubscript 并返回 `Key("")`,丢了 `C[]` 词元。修复:新增 `ParsedAssocSubscript::EmptyBracket`,在两处 match 点映射为 `ArithLValue::InvalidElement`(与 indexed `a[]` 同形);读侧报 badsub ×2(expr.c:1183/1224),绑侧报 invalid-id ×1(variables.c:3403 sh_invalidid,经 expr.c:1052 expr_bind_variable)。队长亲手应用并推送, 见 fix-3252b/REPORT.md。 ## 头 CI 裁定(队长,run 44356117145) census 78,自带钉 19/19 绿;唯一新增格为 issue1902 fd-alias 抖动族 (本修法执行不到该面);goldens 基线二名;CLI 全绿;macOS job cancelled 且 steps 为空(从未运行,非产品红);其余全绿。服务器腿 (lib 双边、-D warnings)待链路恢复后补跑;合入依据为上述已裁定的 头 CI(与 #3920/#3915 同例)。 Refs #3252 ## 本 PR 删除了什么: - 未删除任何产品代码、测试用例或钉。本 PR 只加算术下标诊断发射 (arithmetic/{parser,value,lvalue,mod}.rs、conditional.rs)与回归钉 tests/issue3252…;既有断言保持 GNU 真值不变。
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
…ry faces (Refs #3921) Item 1 — zero-length-match advance: replace_parameter_pattern_inner copied one char past a zero-length match (GNU pat_subst:9286-9304 copies one CHARACTER, and in GNU one carrier byte / one U+E000 char is one character). A raw-byte marker pair (U+E000 + payload) or a literal-char escape pair (U+E400 + char) is one match unit, so the advance now lands on the next unit boundary from the #3920 finder table instead of stranding the cursor inside the pair. Item 2 — literal U+E000 user data, two faces, both oracle-verified against GNU bash 5.3.20 (LC_ALL=C.UTF-8): (a) `printf -v` stored the formatted output raw: the lone U+E000 + payload was read as a raw-byte marker pair at the first decode boundary, so `printf -v v '\uE000\uE001'` stored one NUL byte (len 1, plain expansion NUL, child-env spawn failure). The output is now value-entry encoded (entry_encode_value_text, the bytes_to_shell_text parity every other value channel uses) at the last step before storage, in all four assign_printf_output arms (scalar, indexed, assoc, nameref). (b) `declare -p` double-decoded: decode_to_visible_text folds E400 pairs to lone U+E000s, and the byte-view quoters (strtrans.c ansic_quote port, setattr.def:528-531) re-folded a lone U+E000 + payload-range char into a byte, so `declare -p` showed `$'\000'` for a correctly stored U+E000 U+E001. The display quoters (quote_declare_value, quote_array_element_value, quote_declare_display_value, quote_assoc_display_key, quote_listing_value) now re-spell the visible text as transport text before quoting, so the exactly-once decode yields the visible chars. The genuine-pair arm is unchanged (rubash#540/#1060). Pins: the two item-1 cells were already fail-first red; ten new item-2 cells (printf -v storage + declare -p display) are red on the unfixed base and green with this fix.
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
… advance and display (Refs #3921) ## 根因 #3546 修法(PR #3920,47a24b28)只把三个 replace finder 的候选边界改为匹配单元边界,留下两项边界情形(REPORT §6,即本单): 1. **零长匹配推进切半 pair**:`replace_parameter_pattern_inner` 的零长分支(`cursor = end + ch.len_utf8()`)只复制一个字符。零长匹配恰落在 raw-byte marker 对(U+E000 + payload)或 literal-char escape 对(U+E400 + char)之前时,只复制对的首半、把 `cursor` 丢在 pair 当中;随后扫描在末尾位置又找到一个幻影零长匹配,值以 pair 收尾时多出一个替换(`${w//*(x)/Q}` 在单个 0x14 字节上得 `Q\x14Q`,GNU 为 `Q\x14`)。 2. **字面 U+E000 按一单元走边界**:用户数据里的真 U+E000 在 replace 面须与 removal 侧一致、按一整个匹配单元处理,不得与后随的 payload 区字符拼成一单元、也不得从 escape 半上切开。 ## 修法 - 零长推进步进落到匹配单元边界(与 #3920 的 `marker_pair_split_points` 过滤同构):用已算好的 `indices`(单元边界表)取 `end` 之后第一个边界,整单元复制后推进。 - 字面 U+E000:区分“用户数据里的真 U+E000”与“载体 marker 对的首字符”;若无法干净区分,至少把行为钉死并与 removal 侧对齐(见钉)。 ## GNU 锚点 - subst.c:9184 `pat_subst()` → lib/glob/sm_loop.c:398 `BRACKMATCH()`:载体字节与 U+E000 字符都是数据。 - subst.c:9286-9304:零长匹配后复制一个字符;GNU 里载体字节(一字节)与 U+E000(一字符)各为一个字符。 ## 回归钉 `tests/issue3921_zero_length_pua_boundary_regressions.rs`(5 个 test fn):`*(x)`/`?(x)` 零长推进 15 形(单载体、双载体、两类载体、单斜杠、ASCII guard)、E400 对上的零长推进、字面 U+E000 的 `?`/`[...]`/字面 pattern/`#`/`%`/`*`/`${#}` 16 形、U+E000 + U+E001 不拼合 6 形、comsub 与源码字面两种入口。期望值 = GNU bash 5.3.20 在 LC_ALL=C.UTF-8 下的实测输出。 ## 本 PR 删除了什么 什么也没删除。本 PR 只加回归钉(首提交),随后补修法提交;不删代码、不删测试、不改公开面。 ## UNVERIFIED-BY-CAPTAIN 队长复核前状态:修法提交待补;钉的 fail-first 与修绿腿待新服务器复跑后补记。 ## 队长复核(头 9e90b03,run 44408881460) - census **78**,唯一新增为 issue1902 一格(fd-alias 已知抖动族,修面不可达;上一头 f46d5c8 为 77 零新增,本头仅为空白 rustfmt 折行);自带钉 **9/9 绿**;6 格 PUA 回归全清(issue2884×3、issue824、issue843、issue1927)。 - goldens 仅基线二名;Rust tests / macOS / CLI / cross / darwin / Windows / shell / ledger / niu 全绿。 - 服务器腿(返工车道):6 格对应 stem 全绿(issue2884 7/7、issue824 9/9、issue843 12/12、issue1927 8/8)、自带钉 9/9、全 lib 1280/0 与 base 持平、-D warnings rc=0、卫生全清。返工根因:显示面 5 个 quoter 的 blanket escape_marker_zone_chars(仅含裸 U+E000 时才需重拼)与 patsub 面 push_existing_literal_pair 对 E400+E000 的错误排除。 - base == 现尖,可直接合(Refs-only,合后手关 #3921)。
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.
根因
${v//[...]/r} 的三个 finder(find_parameter_pattern_match / find_parameter_prefix_match / find_parameter_suffix_match)用 pattern_match_length_bound(pattern 原子数)剪候选,但候选边界是 value 的字符边界。载体字节在 value 里是双字符 raw-byte marker 对(U+E000 + payload),单原子 bracket pattern 的 bound = 1,于是唯一能匹配的候选(双字符 pair 切片)被剪掉,匹配器永远见不到它。匹配器本身无缺陷(byte-spelling 门已把 pair 折成一个 byte-char);${v#pat}/${v%pat} 的 removal walk 早已排除 marker-pair split 点(rubash#1261),只有 replace 侧三个 finder 缺了同一排除。
修法:三个 finder 的候选边界改为匹配单元边界(marker_pair_split_points 过滤),parameter_decode.rs 一处可见性提升(fn → pub(in crate::executor));bound 注释由“字符”改为“匹配单元”。不动匹配器、不动 carrier 编解码、不动 pattern 展开;未碰 markers.rs / compound_exec.rs / conditional.rs / continuation.rs / docs/api-ledger.md;[[ =~ ]] 面(#3545)未动。
GNU 锚点:subst.c:9184 pat_subst() → lib/glob/sm_loop.c:398 BRACKMATCH() 按字节比较括号成员;载体字节是数据。
回归钉:tests/issue3546_bracket_carrier_bytes_regressions.rs(3 个 test fn,7 字节 × 3 拼法 + 双载体 + #/%/?/range/单次/无匹配/纯 ASCII guard)。期望值 = issue 记的 GNU 5.3.20 输出,本地 GNU bash 5.2.21 实跑复核一致。
本 PR 删除了什么
未删除任何文件、函数、公开面或测试。仅修改两处既有实现(parameter_replace.rs 三个 finder 的候选边界构造 + 注释、parameter_decode.rs 一个函数的可见性),新增一个回归测试文件。
UNVERIFIED-BY-CAPTAIN
验证腿全部 PENDING:新服务器构建路由中断(egress proxy 在 ssh banner 交换阶段掐断连接,6 次尝试均失败;服务器当时 load 31 / MemAvailable 172M,三路 cargo 构建并行),Simular box 钱包空,X299 隧道断,本 VM 内存不足本地构建门。fail-first、修法树 3/3、全量 lib 对齐、RUSTFLAGS=-D warnings check、hygiene/rustfmt 均待队长在路由恢复后补跑。钉期望值已由本地 GNU bash 实跑背书。
残差(不在本单修,见工作区 REPORT §6):零长匹配恰落 carried byte 前时推进会切半 pair;字面 U+E000 用户数据按一单元走边界(与 removal 侧既有行为一致)。