Repository navigation
fix(script-entry): escape literal marker-zone chars in script text — isolated U+E000 passthrough (#856) - #946
Merged
Merged
Conversation
…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
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),不删任何面与行为。
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
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"printedab(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}printedZZb(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,E000is indistinguishable from a stray pair introducer at every decode boundary (shell_text_to_raw_bytes,decode_raw_byte_markers,decode_to_visible_text), andE000+E0xxis indistinguishable from a real pair — decode-side disambiguation is impossible for theE000+E0xxandE000+E000forms, so the fix had to be at entry.Fix
bytes_to_script_textnow E400-escapes marker-zone chars in valid-UTF-8 spans viamarkers::push_literal_char— the same entry contract the stdin path already applies viabytes_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.-coperand deliberately not escaped: respawned&children receive serialized AST source (compound_execbash_command_source_text) over the same argv channel carrying transport spelling, so re-escaping-ctext would double-escape it. A literal zone char typed into-ctext remains the protocol's documented ambiguous seam (noted in the function comment).markers::fold_literal_char_escapes(E400 + zone char → char) applied inast_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):"...",'...', bare word), literal U+E400 passthroughsourcebuiltin path; script-file vs-sstdin parityE000+E0xxpairs from$'\xNN'/comsub still decodeevalre-parse composes the escape correctlyVerification
cargo test --test issue856_script_pua_literal_regressions— 7/7 pass--test issue843_patsub_pua_escape_regressions(the fix(expand): #843 — E400-escape user PUA codepoints in the patsub replacement pipeline #853 12-case regression set) — green--test issue735_pua_marker_collision --test marker_leak_golden --test issue824_marker_decode_boundary_regressions— green ([bug] Assignment RHS: control-byte var adjacent to live $() leaks U+E000+U+E0xx carrier pair into stored value (argument position clean) — corrupts OMB binaryanomaly/rjorgenson PS1 #296 frozen-protocol coverage unchanged)--test issue396_source_procsub_regressions --test issue426_sourced_exit_regressions --test issue451_source_parse_discard_regressions --test issue354_carrier_comsub_regressions --test issue586_stdin_script_on_demand_regressions --test issue323_patsub_ansi_c_regressions— greencargo fmtclean;cargo test --libdoes not compile on this base commit (pre-existingbuiltins/cd.rstest-module VarTable drift from 4aaedfb, unrelated)Known remaining seams (documented, out of scope)
-coperand with a literal zone char (ambiguous transport channel, see above)declare -p/printf %qstill 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