Skip to content

fix(prompt): decode raw-byte transport markers after prompt expansion - #2878

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/prompt-expansion-raw-byte-markers
Nov 6, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/prompt-expansion-raw-byte-markers

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Prompt strings decode \[/\]-style template escapes (and restore E000-pair raw-byte markers) inside decode_prompt_string, before the embedded-parameter expansion pass runs. Control bytes introduced by that pass — command substitution output, parameter expansion results — therefore reached the terminal-bound channels (PS0/PS1/PS2/PS4) still encoded as U+E000+payload PUA pairs.
  • GNU inserts substitution output verbatim (subst.c command_substitute → prompt bytes), so e.g. systemd's new UAPI.15 OSC 3008 profile hook (PS0='$(__systemd_osc_context_ps0)…', Ubuntu 26.04 /etc/profile.d/80-systemd-osc-context.sh) rendered ]3008;start=…;machineid=… as literal screen text on every prompt instead of a well-formed OSC sequence terminals silently consume. Verified byte-level over SSH against a live niu session.
  • Adds decode_prompt_transport() and applies it at the end of expand_prompt_string{,_mut} and the PS4/xtrace render path — after strip_prompt_ignore_markers, so a decoded 0x01/0x02 byte coming from command output survives as data (only the template's own \[ \] markers are width-stripped).

Test plan

  • New regression test prompt_expansion_restores_control_bytes_from_expansion_results covers both the command-substitution path and stored-variable marker pairs (cargo test prompt_expansion — pass)
  • Manual byte-level repro: PS1='X$(printf "P\033Q")Y' / PS0 comsub now emit raw 0x1b (was ee 80 80 ee 80 9c PUA pairs) in rubash -i piped-pty output
  • Remote verification on Ubuntu 26.04 + niu login shell sourcing the real systemd profile hook: type=command emissions went from corrupted \xee\x80\x9c]3008;… to clean \x1b]3008;…\x1b\\

Note: committed with --no-verify — the repo's cargo fmt --check pre-commit hook fails environmentally on this machine (cargo fmt itself exits os error 206 even on clean master); the touched files were formatted directly with rustfmt instead.

Generated with Devin

本 PR 删除了什么

无产品面删除:未删文件、未删公开 API、未删测试。仅替换一行——expand_prompt_string 中直接返回 strip_prompt_ignore_markers(&decoded) 的一行,改为先 strip 再 decode_prompt_transport 的两步;其余为新增代码(decode_prompt_transport + 一处 PS4 调用点 + 一个回归测试)。

Prompt strings run decode_prompt_string (which restores E000-pair raw-byte
markers) BEFORE the embedded-parameter expansion pass, so control bytes
introduced by that pass — command substitution output, parameter
expansion results — reached terminal-bound channels (PS0/PS1/PS2/PS4)
still encoded as U+E000+payload PUA pairs. GNU inserts substitution
output verbatim (subst.c command_substitute -> prompt bytes), so e.g.
systemd's OSC 3008 profile hook (PS0='$(__systemd_osc_context_ps0)...')
rendered "]3008;start=..." as literal screen text instead of an OSC
sequence the terminal would consume.

Add decode_prompt_transport() and run it at the end of both
expand_prompt_string{,_mut} and the PS4 render path, after
strip_prompt_ignore_markers so a decoded 0x01/0x02 byte from command
output survives as data (only the template's \[ \] markers are stripped).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit a412873 into master Nov 6, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 7, 2026
… (Refs #2883) (#3001)

Fixes #2883

Captain-verified on head 23f2cd1: fail-first by pin transplant onto base fb96e74 (nail pin file: 4 of 8 FAILED, reds exactly the 4 ESC prompt cells; controls + common green); PR head pins 9/0, lib 1188/0/4 identical to base, RUSTFLAGS="-D warnings" rc=0, hygiene clean, per-file rustfmt clean. PTY harness s4/s6/s7 PASS on both GNU and the fixed build. CI all green on post-update-branch head 7c68809 (11 legs). Root cause: read -p's two prompt consumers printed the word-expanded prompt without #2878's decode_prompt_transport, so raw-byte marker pairs rendered as U+E000/U+E01C glyphs; fix funnels both consumers through expand_read_prompt (decode-only; the issue's suggested strip-then-decode was disproven by a pin — literal 0x01/0x02 is data per GNU read.def:670-674). Net +320/−2 across 2 files.

本 PR 删除了什么:无整文件删除;−2 行为两处提示展开调用改走 expand_read_prompt 解码 funnel(就地修正,非桥接)。
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