Skip to content

fix(script-entry): escape literal marker-zone chars in script text — isolated U+E000 passthrough (#856) - #946

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/856
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/856

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes #856 — an isolated literal U+E000 (and any literal marker-zone char U+E000..=U+E401) in script text was decoded as a malformed #296 raw-byte pair introducer and silently dropped:

  • v="a<U+E000>b"; echo "$v" printed ab (GNU: a + EE 80 80 + b)
  • v="a<U+E000><U+E001>b" decoded as a byte-0x00 pair (GNU: both glyphs verbatim)
  • v="a<U+E000><U+E000>b" collapsed to one glyph (GNU: both)
  • ${v//a/ZZ} printed ZZb (GNU: ZZ + glyph)

Root cause

bytes_to_script_text (substitution_metadata.rs — the single fresh-source decoder for script files, source, and init files) left valid UTF-8 untouched, so a literal zone char entered transport text bare. Once bare, E000 is indistinguishable from a stray pair introducer at every decode boundary (shell_text_to_raw_bytes, decode_raw_byte_markers, decode_to_visible_text), and E000+E0xx is indistinguishable from a real pair — decode-side disambiguation is impossible for the E000+E0xx and E000+E000 forms, so the fix had to be at entry.

Fix

  • bytes_to_script_text now E400-escapes marker-zone chars in valid-UTF-8 spans via markers::push_literal_char — the same entry contract the stdin path already applies via bytes_to_shell_text (read_unbuffered_line). Script bytes are provably fresh source, so every zone char is user data; byte-exact vs GNU on all pinned forms, and script-file output now matches the stdin baseline byte-for-byte.
  • -c operand deliberately not escaped: respawned & children receive serialized AST source (compound_exec bash_command_source_text) over the same argv channel carrying transport spelling, so re-escaping -c text would double-escape it. A literal zone char typed into -c text remains the protocol's documented ambiguous seam (noted in the function comment).
  • Display side: new markers::fold_literal_char_escapes (E400 + zone char → char) applied in ast_print (--pretty-print, declare -f, type) so printed source shows the user's original chars rather than leaking the transport escape.

Tests

New tests/issue856_script_pua_literal_regressions.rs (7 tests, script-file entry per the issue's methodology):

  • three pinned forms + patsub reproduction, byte-exact vs GNU
  • all quoting shapes ("...", '...', bare word), literal U+E400 passthrough
  • source builtin path; script-file vs -s stdin parity
  • protocol non-regression: real E000+E0xx pairs from $'\xNN'/comsub still decode
  • eval re-parse composes the escape correctly

Verification

Known remaining seams (documented, out of scope)

  • -c operand with a literal zone char (ambiguous transport channel, see above)
  • declare -p / printf %q still lose an isolated E000 on an already-escaped value (a second decode boundary sees decoded text; identical on stdin pre-change — separate locus)

Refs #296 #853 #843

…isolated U+E000 is user data, not a stray pair introducer (#856)

A literal U+E000..=U+E401 char in a script file (`v="a<U+E000>b"`) reached
the transport layer unescaped, so every decode boundary read the bare
E000 as the #296 raw-byte pair introducer and ate it: `echo "$v"` printed
`ab`, `${v//a/ZZ}` printed `ZZb`, and `a<U+E000><U+E001>b` decoded as a
byte-0x00 pair. GNU bash 5.3.0 keeps the PUA glyph verbatim in all three
forms plus the patsub reproduction (issue discussion, WSL oracle).

`bytes_to_script_text` (the single fresh-source decode for script files,
`source`, and init files) now E400-escapes marker-zone chars in valid
UTF-8 spans via markers::push_literal_char — the same entry contract the
stdin path already applies through bytes_to_shell_text. The `-c` operand
is deliberately excluded: respawned `&` children receive serialized AST
source over that argv channel and re-escaping would double-escape it
(documented in the function comment).

ast_print gains the display-side inverse fold_literal_char_escapes
(E400 + zone char -> char) so --pretty-print / declare -f print the
user's source spelling instead of leaking the transport escape.

Refs #856
Refs #296
@caomengxuan666
caomengxuan666 merged commit a692b20 into master Oct 20, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/856 branch October 30, 2026 01:41
caomengxuan666 added a commit that referenced this pull request Nov 6, 2026
…host adoption niu #946) (#2887)

Refs #2859

账本记账补正(GAP-13 先例的计数补升步):niu #946(宿主接线,merge `28720f2f`)已合,`Session::background_job_count` 在宿主侧有了恰好 1 处生产调用(`prompt_for_display` 里 `session_mut().background_job_count()`,队长已在 niu 树上 rg 核过:生产调用 1 处,其余命中为钉与注释)。本 PR 把账本 §2.3 该行计数 0 → 1 并把行文从「staged 待接线」改为已接线记录。§6 总数不变(281),`check-api-ledger.py` 通过(281/281)。

本 PR 合入后另起 niu 镜像 PR 把同一文件同步过去,两仓账本恢复逐字节一致,#2859 随即由队长以证据评论关单(本 PR 只 Refs,不自动关)。

## 本 PR 删除了什么

无删除:一行计数与行文的记账更新(+1/−1),不删任何面与行为。
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.

patsub 替换文本中孤立字面 U+E000 按畸形 raw-byte 对解码(#296 E000 所有权协议的不可表示类)——#853 CR NIT-3

1 participant