Skip to content

fix(read): decode raw-byte marker pairs in interactive read -p prompt (Refs #2883) - #3001

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2883-read-prompt-carrier
Nov 7, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2883-read-prompt-carrier

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Refs #2883

根因

Interactive read -p renders its prompt argument's raw-byte marker pairs literally: a prompt containing ESC displays EE 80 80 EE 80 9C (the U+E000/U+E01C pair glyphs) instead of the ESC byte. GNU emits the byte.

The expanded prompt word carries control bytes as raw-byte marker pairs (transport encoding, src/executor/markers.rs). PR #2878 added the post-expansion decode (decode_prompt_transport) at the three PS0/PS1/PS2/PS4 sites, but the read -p prompt travels a different display path — read builtin → stderr print (non-edit) / line editor (edit) — and both of its consumers in src/executor/read_builtin.rs used the raw expand_word result undecoded:

  • the display print (eprint! after read_prompt_should_display), and
  • read_edit_prompt, consumed by the line-editor repaint in src/executor/read_io.rs.

GNU 锚点

  • builtins/read.def:316 — prompt = list_optarg: the prompt is the word-expanded argument.
  • builtins/read.def:670-674 — non-edit path prints the expanded bytes verbatim: fprintf(stderr, "%s", prompt).
  • builtins/read.def:697 — edit path hands the same bytes to edit_line(prompt, …).
  • No prompt-escape decoding applies to read -p (\[ in the prompt argument stays literal text — pinned as a control cell).

修法

src/executor/read_builtin.rs 新增 Executor::expand_read_prompt,两个消费点统一改走它:expand_word 之后接 decode_prompt_transport,把 marker 对还原为真实字节。机制级单点收敛,不是逐症状补丁。

一处按证据收窄:issue 建议的 strip-then-decode 全镜像经钉验证不成立——本通道没有制造 prompt-ignore 标记的模板阶段,展开词中的字面 0x01/0x02 只能是 prompt 数据(GNU fprintf 逐字节输出),strip 会把它吃掉(钉 read_p_prompt_keeps_decoded_sx01_data_byte 在 strip 版下实测变红、decode-only 下绿;GNU oracle 对字面与 comsub 两形态均确认输出真 0x01 字节)。故本 PR 只做 decode:issue 括注的目标(解码出的 0x01/0x02 数据存活)对字面与对编码两种形态都达成。

钉(tests/issue2883_read_prompt_carrier_regressions.rs,script(1) PTY、字节级断言):

  • fail-first(base fb96e741):4 个 ESC 渲染格全红($'…' 参数 = sweep s4 形、变量值、comsub、-e 编辑器 repaint),typescript 实证 prompt 渲染为 <A<U+E000><U+E01C>B>;
  • 修后 9 passed / 0 failed(7 格 + common harness 2 测);全量 lib 1188/0/4 与 base 逐数一致;RUSTFLAGS="-D warnings" rc=0;hygiene clean;rustfmt clean;
  • 审计定速 PTY harness(job-control 父形态)复跑:s4 + \x01 两格对 GNU 与修后二进制 PASS (both);
  • -e 格改分段投喂:一次性灌入会与 REPL 预读抢答行(harness 竞态,定速探针实证 read 正常完成),非产品缺陷。

本 PR 删除了什么

无删除。仅在 read builtin 的 prompt 展开点接入既有的 decode_prompt_transport,外加新增钉文件。未碰 src/lexer/continuation.rs,未改 docs/api-ledger.md,无新公开 API 面。

UNVERIFIED-BY-CAPTAIN

…2883)

Fail-first on master fb96e74: the four ESC-rendering cells fail
($'...' argument, variable value, command substitution, -e editor
repaint) — the prompt renders U+E000/U+E01C raw-byte marker pairs
instead of the ESC byte. Two control cells (0x01 data byte, literal
backslash-brackets) already pass. GNU: builtins/read.def:316
(prompt is the word-expanded argument), read.def:670-674 (verbatim
stderr print), read.def:697 (edit_line hand-off). Seed: #2879 sweep
PTY cell s4.
…ry (Refs #2883)

Both read-prompt consumers in read_builtin.rs (the stderr print and
the line editor's read_edit_prompt) used the raw expand_word result,
so control bytes arrived as U+E000 marker pairs and rendered as pair
glyphs. New Executor::expand_read_prompt funnels both sites through
decode_prompt_transport — GNU builtins/read.def:316 (prompt is the
word-expanded argument), :670-674 (verbatim stderr print), :697
(edit_line hand-off).

Decode only, no strip: this channel has no template stage that
manufactures prompt-ignore markers, so a literal 0x01/0x02 in the
expanded word is prompt DATA GNU prints verbatim; the new pin cell
proves a strip step eats it (the strip-then-decode mirror from the
issue was tested and narrowed on this evidence). Pair-encoded
0x01/0x02 decode back to the same data bytes.

Pins: 4 ESC cells red on base now green; adds pair-encoded-0x01
comsub cell; -e cell switched to paced PTY input (all-at-once writes
race the REPL read-ahead — harness artifact, captain-verified paced
probe completes the read). Test file also carries its rustfmt
reflow.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 7, 2026 18:54
@caomengxuan666
caomengxuan666 merged commit 6eb861b into master Nov 7, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 8, 2026
…2885)

- markers.rs census: add EXACT entry for __RUBASH_CURRENT_FILE
  (new carrier from #3035/#3047, missing from the E8 census).
- marker_registry_roundtrips: remove all four TYPED_DATA_EXCEPTIONS
  (E002 shapes 1-3 fixed by #2882/#3006; E316 shape 3 by #3016/#3041);
  the stem now asserts every shape round-trips.
- marker-lint-allowlist: delete the two #2882 KNOWN BLIND SPOT entries
  (their own text said delete when #2882 lands), plus two entries made
  stale by master-side changes: set.rs ESC rendering entry (#3044
  restructured the table) and command_prepare contains:QUOTED_NULL_MARKER
  (#3006 converted those consumers to E400-aware helpers).
- marker_leak_golden_pty: un-ignore the read -p cell (#3001 landed the
  read -p decode).
- marker_leak_golden: set-listing C0 scalar cell now expects the
  ansic-quoted GNU form (rubash#3017/#3044), byte-verified against
  GNU bash 5.3.20; the no-marker assertion is unchanged.

Verified on the merged tree (merge bd87ed1 + this commit):
lint OK (117 consts / 258 sites), registry 10/0, PTY 2/0,
golden 20/0, lib 1200/0/4, -D warnings rc=0, hygiene/fmt/CR clean.
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