Expand description
script_bytes submodule (Rust-only; see the module docs).
!!! WARNING: RUST-ONLY MODULE — NO C COUNTERPART !!!
Lossless decode of RAW SCRIPT BYTES into the shell pipeline’s
String form.
C zsh has no encoding requirement on script input. Src/input.c
reads bytes (shingetchar, c:229) and Src/utils.c:4856 metafy
escapes only the reserved IMETA bytes (Src/utils.c:4195-4201 —
'\0', Meta 0x83, Marker 0xa2 and the token range
Pound..Nularg); every other byte, including a lone ISO-8859-1
0xe9, travels through the lexer untouched and is written back
out verbatim. That is why a legacy byte in a completion file has
never bothered zsh.
Rust String is UTF-8, so a raw non-UTF-8 byte cannot be stored
directly. zshrs already has one encoding for exactly this, used by
the $'\xNN' decoders (src/ported/lex.rs getkeystring_dollar_quote,
src/extensions/compile_zsh.rs meta_encode_byte) and decoded at
every write/exec boundary by crate::ported::utils::unmetafy_str:
a byte >= 0x80 becomes the two chars U+0083 (Meta) and
U+00(b ^ 32). This module applies that same encoding to the
bytes a script file or SHIN hands us.
The transform is the byte-level twin of Src/input.c:267 shingetline, which the interactive/stdin path already performs
inline: valid UTF-8 stays real chars (the lexer is Unicode-based
— src/ported/lex.rs:6171 “zshrs does not metafy, it keeps UTF-8
str”), and only bytes that cannot be part of a UTF-8 sequence
are Meta-encoded. Clean-ASCII and valid-UTF-8 input therefore
decode to exactly the same String read_to_string produced, so
the common path is unchanged; the difference is that an invalid
byte no longer kills the read.
Functions§
- decode_
script_ bytes - Decode raw script bytes into the pipeline’s
Stringform without losing a single byte. - read_
script_ file - Read a script file as raw bytes and decode it losslessly.
- regroup_
meta_ utf8 - Regroup the Meta-pair bytes a
$'…'decoder produced.