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

+17 -4
View File
@@ -109,7 +109,7 @@ pub struct Config {
pub cursor_blink: Option<bool>,
pub working_directory: Option<EncodedOs>,
pub resources_dir: Option<EncodedOs>,
pub term: String,
pub term: EncodedOs,
pub rt_pre_exec_info: RtPreExecInfo,
pub rt_post_fork_info: RtPostForkInfo,
@@ -124,7 +124,7 @@ pub struct Config {
impl Config {
/// A config with Zig-struct-style defaults for everything optional.
pub fn new(env: EnvMap, term: impl Into<String>) -> Config {
pub fn new(env: EnvMap, term: EncodedOs) -> Config {
Config {
command: None,
env,
@@ -134,7 +134,7 @@ impl Config {
cursor_blink: None,
working_directory: None,
resources_dir: None,
term: term.into(),
term,
rt_pre_exec_info: RtPreExecInfo::default(),
rt_post_fork_info: RtPostForkInfo::default(),
create_scope: None,
@@ -801,7 +801,8 @@ impl Subprocess {
// For now, we just look up a bundled dir but in the future we should
// also load the terminfo database and look for it.
if let Some(base) = &cfg.resources_dir {
env.insert("TERM", cfg.term.clone());
// The configured TERM is an encoded OS string: export its bytes.
env.insert("TERM", cfg.term.to_os());
env.insert("COLORTERM", "truecolor");
// Assume that the resources directory is adjacent to the terminfo
@@ -1586,6 +1587,18 @@ mod tests {
);
}
#[test]
fn configured_term_is_exported_decoded() {
use std::os::unix::ffi::OsStrExt;
let dir = ghostty_os::TempDir::init().unwrap();
for raw in [&b"x\xfft"[..], "t\u{fdd0}".as_bytes()] {
let mut cfg = Config::new(EnvMap::new(), EncodedOs::from_bytes(raw));
cfg.resources_dir = Some(EncodedOs::from_path(&dir.path()));
let exec = Exec::new(cfg).unwrap();
assert_eq!(exec.env().unwrap().get("TERM").unwrap().as_bytes(), raw);
}
}
#[test]
fn exec_command_darwin_hushlogin_with_non_utf8_home() {
use std::os::unix::ffi::OsStrExt;