fix: systematic byte fidelity for config strings and RV7 gaps

Resolves the 9 gap groups in docs/rewrite/notes/review-rv7-codex.md and
audits every string-typed config field against its consumers
(field -> consumers -> decode status table in final-Z9.md):
- Windows EnvMap keys use a port of Zig's nls.zig uppercase table
  (upcaseW); Windows locale init follows Zig's chain (setlocale +
  _putenv_s); malformed WTF-8 now fails process launch conversions like
  Zig instead of substituting U+FFFD; kitty file paths convert WTF-8.
- bash --rcfile/--init-file, configured TERM and inherited GTK LANG
  keep their original bytes.
- C API clipboard completion and ghostty_surface_binding_action take
  bytes; complete_clipboard_request is byte-typed through the core.
- text:/csi:/esc: bindings, enquiry-response, input = path:, embedded
  initial_input, search needles, titles, link regexes, clipboard
  codepoint map, command palette text and GTK font/namespace values
  decode the escape encoding before use.

Remaining by design: D-Bus a{ss} values and +new-window arguments are
UTF-8 by D-Bus type. C API key/preedit text follows separately.

Test Plan:
- cargo test --workspace
- just check-macos (both), just check-windows, just check-wasm
This commit is contained in:
ddidderr committed 2026-10-12 10:50:20 +02:00
1 parent ffc91c31e4
commit af094276f8
40 files changed
+986 -167

No files matched your search

+24 -6
View File
@@ -2,6 +2,8 @@
use std::fmt;
use ghostty_os::osbytes::EncodedOs;
use crate::{
cli_args::{ArgError, ConfigField, split_tagged_union},
formatter::EntryFormatter,
@@ -16,8 +18,11 @@ use crate::{
/// might be produced in an intermediate state.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ReadableIO {
/// Raw bytes in the reversible OS-byte encoding (decode with
/// `osbytes::config_str_to_bytes` after [`ReadableIO::clone_parsed`]).
Raw(String),
Path(String),
/// A file path (decode with `EncodedOs::to_path` before opening).
Path(EncodedOs),
}
impl Default for ReadableIO {
@@ -34,7 +39,9 @@ impl ReadableIO {
// Parsing can't fail because we validate it in parse_cli
match self {
ReadableIO::Raw(v) => ReadableIO::Raw(string::parse(v).unwrap_or_default()),
ReadableIO::Path(v) => ReadableIO::Path(string::parse(v).unwrap_or_default()),
ReadableIO::Path(v) => ReadableIO::Path(EncodedOs::from_encoded(
string::parse(v.as_encoded()).unwrap_or_default(),
)),
}
}
}
@@ -55,7 +62,7 @@ impl ConfigField for ReadableIO {
let (tag, rest) = split_tagged_union(input);
*self = match tag {
"raw" => ReadableIO::Raw(rest.to_string()),
"path" => ReadableIO::Path(rest.to_string()),
"path" => ReadableIO::Path(EncodedOs::from_encoded(rest)),
_ => ReadableIO::Raw(input.to_string()),
};
Ok(())
@@ -63,8 +70,8 @@ impl ConfigField for ReadableIO {
fn format_entry(&self, f: &mut EntryFormatter<'_>) -> fmt::Result {
let (tag, v) = match self {
ReadableIO::Raw(v) => ("raw", v),
ReadableIO::Path(v) => ("path", v),
ReadableIO::Raw(v) => ("raw", v.as_str()),
ReadableIO::Path(v) => ("path", v.as_encoded()),
};
writeln!(f.writer, "{} = {tag}:{v}", f.name)
}
@@ -126,7 +133,18 @@ mod tests {
io.parse_cli(Some("raw:foo")).unwrap();
assert_eq!(io, ReadableIO::Raw("foo".into()));
io.parse_cli(Some("path:foo")).unwrap();
assert_eq!(io, ReadableIO::Path("foo".into()));
assert_eq!(io, ReadableIO::Path(EncodedOs::from_plain_text("foo")));
}
#[test]
fn readable_io_path_decodes_to_the_original_bytes() {
let mut io = ReadableIO::default();
let enc = EncodedOs::from_bytes(b"/tmp/\xffin").into_encoded();
io.parse_cli(Some(&format!("path:{enc}"))).unwrap();
let ReadableIO::Path(p) = io.clone_parsed() else {
panic!("path expected")
};
assert_eq!(p.to_bytes(), b"/tmp/\xffin");
}
#[test]