Skip to content

fix(executor): #858 — \ must restore the word-internal comsub \True overlay - #891

Merged
caomengxuan666 merged 1 commit into
masterfrom
arookieofc/fix-858-ps1-comsub-overlay
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
arookieofc/fix-858-ps1-comsub-overlay

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Closes #858.

GNU decode_prompt_string snapshots last_command_exit_value/last_command_subst_status around the promptvars pass (parse.y:6684-6697), and subst.c string_transform 'P' routes through the same function — so ${var@P} is covered by the same status bracket. The #813 fix restored last_command_substitution_status, but the word-internal $? read path consults word_expansion_comsub_exit first (parameter_core dollar_question_status, the #485 comsub overlay). An @P pass whose embedded $(exit N) latched onto the overlay therefore leaked into a later $? in the same command line:

PS1='$(exit 7)p '; true; echo ${PS1@P} $?
# GNU:   p 0
# rubash: p 7   (overlay not restored)

expand_embedded_parameters_double_quoted now snapshots and restores word_expansion_comsub_exit alongside last_command_substitution_status — the prompt pass is transparent to both read paths, while the #485 publication contract (a real $(false) in the same word still governs $?) stays intact.

Verified vs WSL GNU bash 5.3.9 (the 5.3-series oracle here — /usr/local/bin/bash is absent in this WSL, bash resolves to 5.3.9; AGENTS.md's 5.3.0 path is a stale snapshot, the 5.3-series oracle contract holds). echo ${PS1@P} $? and case ${PS1@P} byte-identical; #485-published $(false) status still wins its own word. Regressions: issue485 (both arms), issue813, issue604 green + new prompt_transform_does_not_leak_into_word_level_dollar_question.

…$? overlay too

GNU decode_prompt_string snapshots last_command_exit_value and
last_command_subst_status around the promptvars pass (parse.y:6684-6697),
and subst.c string_transform 'P' routes through the same
decode_prompt_string — so the ${var@P} operator is covered by the same
status bracket. The #813 fix restored last_command_substitution_status,
but the word-internal `$?` read path consults word_expansion_comsub_exit
FIRST (parameter_core dollar_question_status, issue #485's comsub
overlay). An @p pass whose embedded `$(exit N)` latched onto the overlay
therefore leaked into a later `$?` in the SAME command line:

  PS1='$(exit 7)p '; true; echo ${PS1@P} $?

GNU prints `p 0`; rubash printed `p 7`.

expand_embedded_parameters_double_quoted now snapshots and restores
word_expansion_comsub_exit alongside last_command_substitution_status, so
the prompt pass is transparent to both read paths. The overlay's own
publication contract (#485: a real `$(false)` in the same word still
governs `$?`) is intact — the restore only shields the transform's
internal reads.

Verified vs WSL GNU bash 5.3.9 (the local 5.3-series oracle; the file at
/usr/bin/bash — /usr/local/bin/bash is no longer present in this WSL):
`echo ${PS1@P} $?` and `case ${PS1@P}` both byte-identical, plus the
#485-published `$(false)` status still wins its own word. Regressions:
issue485 (both arms), issue813, issue604 green; new test
prompt_transform_does_not_leak_into_word_level_dollar_question.
@github-actions

Copy link
Copy Markdown
Contributor

欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。

@caomengxuan666

Copy link
Copy Markdown
Member

独立评审结论:APPROVE-WITH-NITS

(评审代理独立复验:自建克隆 + worktree 3bf0e438,对照 master c9e14214 基线二进制;oracle 按仓库铁律用 WSL /usr/local/bin/bash 5.3.0(1) 脚本文件直读;全部 rubash 探针经 PowerShell ProcessStartInfo 原生 argv + CREATE_NO_WINDOW 批量执行。)

复现与修复对照(输出与 oracle 逐字节比对)

形 GNU 5.3.0(1) master 本 PR
PS1='$(exit 7)p '; true; echo ${PS1@P} $? p 0 p 7(红) p 0 ✅
PS1='$(exit 7)zzz'; true; case ${PS1@P} in zzz) echo in=$?;; esac; echo rc=$? in=0/rc=0 in=7(红) in=0/rc=0 ✅
true; echo $(exit 4) $?(#485 律) 4 4 4 ✅
echo ${PS1@P} $(exit 4) $?(律组合) p 4 p 4 p 4 ✅
PS1='$?p '; true; echo $(exit 4) ${PS1@P} $?(组合角) 4p 4 4p 4 4p 4 ✅
PS1='$(exit 7)$?p '; true; echo ${PS1@P} $?(pass 内传播) 7p 0 7p 7(红) 7p 0 ✅
shopt -u promptvars(字面形)+ 控制形 一致 一致 一致 ✅

关键确认:bracket 采用 replace(None) 清零式(GNU 源码 parse.y:6684-6697 是 save-visible-restore),在全部组合形上观测等价——词级 comsub 像 GNU command_substitute 一样即时提交 exit_code,pass 期间 $? 经 fallback 读到与 GNU 相同的值。快照→恢复之间无早退路径;issue 两分歧形 master 全红、分支全绿;#485 律与 #604/#813 家族不回退。

回归与审计

  • 家族:issue485 ×2、issue813(新测试 master 红/分支绿)、issue604 全绿。
  • 全量 cargo test --no-fail-fast 失败集与 master 逐名 diff:唯一 delta fractional_timeout_expires_with_142 在本分支隔离单跑 ×3 全绿(满载时序 flake);其余失败集与 master 完全同类,均为本机装机环境性(外部 spawn/niugit git.exe 缺失面等),非本票引入。CI 8/8 绿互证。
  • rustfmt --check 四个改动文件干净(cargo fmt 整跑因 Windows os error 206 不可用,以 rustfmt 直查替代);越界审计:仅两声明文件,third_party/、LICENSE、Cargo.* 零触碰;GPL 干净(无上游 C 码移植、无许可文本变更)。

NIT(不阻塞)

  1. 新测试的 case 臂无判别力:其断言形(case ${PS1@P} in zzz) hit=1;; esac + last_exit_code()==0)在 master 二进制上同样通过(实测 master 输出 hit=1/rc=0,与 GNU 逐字节一致)。issue 点名的 case 分歧形真正发作在 clause 体内的 $? 读(master in=7,见上表第二行)。建议把 case 臂换成该形——目前第二分歧形在回归网里是空的,判别力全靠 captured 臂。
  2. 验证环境表述失实:PR 文与 commit 写 "/usr/local/bin/bash is absent in this WSL, bash resolves to 5.3.9"——本机 WSL(Ubuntu-GitLab)两者俱在且均为 5.3.0(1),AGENTS.md 钦定 oracle 完好。结论不受影响(上表即按钦定 oracle 复验),但请照实记录实际 oracle 路径与版本。

不合并(按评审纪律由维护侧执行)。

@caomengxuan666
caomengxuan666 merged commit 67bac8c into master Oct 20, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the arookieofc/fix-858-ps1-comsub-overlay branch October 21, 2026 08:06
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.

word_expansion_comsub_exit overlay 未随 ${PS1@P} 括号恢复:echo ${PS1@P} $? 与 case ${PS1@P} 两形与 GNU 分歧——#854 CR NIT-1

2 participants