refactor(config): parse config values from raw bytes like Zig
Zig parses config values (cli/args.zig, Config.zig field parsers, config/string.zig) from raw byte slices, and each field type decides whether it requires UTF-8 (InvalidValue otherwise) or stores bytes. The port escape-encoded raw bytes into Strings at the line reader and let fields parse the escaped text, so fields could observe encoding artifacts; successive audits kept finding such leaks (RV5-RV8). Field parsers now receive the original bytes: text fields validate UTF-8 where Zig does, byte/path fields store bytes (EncodedOs/OsString). This resolves all 9 RV8 findings (docs/rewrite/notes/review-rv8-codex.md), each with a regression test: Windows path conversion fails with BadPathName instead of substituting U+FFFD; Windows process launch uses strict UTF-8 like Zig's Command; the WTF-8 decoder accepts paired- surrogate encodings like Zig; literal U+FDD0 Unicode key triggers; selection-word-chars and clipboard-codepoint-map reject invalid UTF-8; font style / codepoint-map family names use original bytes; C title actions forward bytes; D-Bus new-window/Flatpak conversions match Zig. Design, sweep and validation: docs/rewrite/notes/final-bytes-refactor.md. Also moves the bundled iTerm2-Color-Schemes license out of resources/themes/ so +list-themes no longer lists it as a theme (output is now byte-identical to Ghostty 1.3.1). Done by Codex (gpt-6-astra), reviewed and verified by the orchestrator. Test Plan: - cargo test --workspace --no-fail-fast (3428 passed, exit 0) - just check-macos (both), just check-windows, just check-wasm - +show-config --default --docs, +list-keybinds, +list-actions --docs, +list-themes --plain compared with /usr/bin/ghostty
This commit is contained in:
1 parent
37a1646611
commit
672e8a4ae1
100 files changed
+2310
-1054
No files matched your search
@@ -720,7 +720,7 @@ impl Surface {
|
||||
};
|
||||
// The payload is a config string in the reversible OS-byte
|
||||
// encoding: the pty gets the original bytes.
|
||||
full.extend(ghostty_os::osbytes::config_str_to_bytes(data));
|
||||
full.extend(data.to_bytes());
|
||||
// Zig formats into a fixed 128 byte buffer (`NoSpaceLeft`).
|
||||
if full.len() > 128 {
|
||||
return Err("csi/esc binding sequence too long (max 128 bytes)".into());
|
||||
@@ -734,10 +734,10 @@ impl Surface {
|
||||
Action::Text(data) => {
|
||||
// Decoded bytes: escapes produce UTF-8, everything else is
|
||||
// copied byte for byte (Zig `config/string.zig`).
|
||||
let text = match ghostty_config::string::parse_bytes(data) {
|
||||
let text = match ghostty_config::string::parse_bytes(data.to_bytes()) {
|
||||
Ok(t) => t,
|
||||
Err(err) => {
|
||||
log::warn!("error parsing text binding text={data} err={err:?}");
|
||||
log::warn!("error parsing text binding text={data:?} err={err:?}");
|
||||
return Ok(true);
|
||||
}
|
||||
};
|
||||
@@ -824,9 +824,7 @@ impl Surface {
|
||||
s.handle
|
||||
// The payload is a config string in the reversible
|
||||
// encoding: search for the original bytes.
|
||||
.send(SearchMessage::ChangeNeedle(
|
||||
ghostty_os::osbytes::config_str_to_bytes(text),
|
||||
));
|
||||
.send(SearchMessage::ChangeNeedle(text.to_bytes()));
|
||||
s.handle.wakeup();
|
||||
}
|
||||
}
|
||||
@@ -934,15 +932,11 @@ impl Surface {
|
||||
}
|
||||
|
||||
Action::SetSurfaceTitle(v) => {
|
||||
return Ok(self.perform(RtAction::SetTitle(SetTitle {
|
||||
title: ghostty_os::osbytes::config_str_to_text(v),
|
||||
})));
|
||||
return Ok(self.perform(RtAction::SetTitle(SetTitle { title: v.clone() })));
|
||||
}
|
||||
|
||||
Action::SetTabTitle(v) => {
|
||||
return Ok(self.perform(RtAction::SetTabTitle(SetTitle {
|
||||
title: ghostty_os::osbytes::config_str_to_text(v),
|
||||
})));
|
||||
return Ok(self.perform(RtAction::SetTabTitle(SetTitle { title: v.clone() })));
|
||||
}
|
||||
|
||||
Action::ClearScreen => {
|
||||
@@ -1330,7 +1324,7 @@ mod tests {
|
||||
// action's EncodedOs decodes back to the same path.
|
||||
assert_eq!(path_bytes(&path), path.as_os_str().as_bytes());
|
||||
let url = ghostty_os::osbytes::EncodedOs::from_path(&path);
|
||||
assert_eq!(url.to_path(), path);
|
||||
assert_eq!(url.to_path().unwrap(), path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user