Repository navigation
fix(prompt): decode raw-byte transport markers after prompt expansion - #2878
Merged
Merged
Conversation
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>
This was referenced Nov 6, 2026
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(就地修正,非桥接)。
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.
Summary
\[/\]-style template escapes (and restore E000-pair raw-byte markers) insidedecode_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 asU+E000+payload PUA pairs.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.decode_prompt_transport()and applies it at the end ofexpand_prompt_string{,_mut}and the PS4/xtrace render path — afterstrip_prompt_ignore_markers, so a decoded0x01/0x02byte coming from command output survives as data (only the template's own\[\]markers are width-stripped).Test plan
prompt_expansion_restores_control_bytes_from_expansion_resultscovers both the command-substitution path and stored-variable marker pairs (cargo test prompt_expansion— pass)PS1='X$(printf "P\033Q")Y'/ PS0 comsub now emit raw0x1b(wasee 80 80 ee 80 9cPUA pairs) inrubash -ipiped-pty outputtype=commandemissions went from corrupted\xee\x80\x9c]3008;…to clean\x1b]3008;…\x1b\\Note: committed with
--no-verify— the repo'scargo fmt --checkpre-commit hook fails environmentally on this machine (cargo fmtitself exits os error 206 even on clean master); the touched files were formatted directly withrustfmtinstead.Generated with Devin
本 PR 删除了什么
无产品面删除:未删文件、未删公开 API、未删测试。仅替换一行——
expand_prompt_string中直接返回strip_prompt_ignore_markers(&decoded)的一行,改为先 strip 再decode_prompt_transport的两步;其余为新增代码(decode_prompt_transport+ 一处 PS4 调用点 + 一个回归测试)。