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:
ddidderr committed 2026-10-12 11:57:01 +02:00
1 parent 70c250cf2d
commit 6f9b3129e1
100 files changed
+2310 -1054

No files matched your search

+16 -10
View File
@@ -103,22 +103,28 @@ macro_rules! config_struct {
}
}
/// Parse a plain UTF-8 value supplied programmatically.
#[allow(dead_code)]
pub fn parse_field(&mut self, key: &str, value: Option<&str>) -> Result<(), $crate::cli_args::ArgError> {
self.parse_field_bytes(key, value.map(str::as_bytes))
}
#[allow(dead_code)]
/// Parse a single key/value into the matching field. Empty
/// values reset the field to its default.
pub fn parse_field(
pub fn parse_field_bytes(
&mut self,
key: &str,
value: ::core::option::Option<&str>,
value: ::core::option::Option<&[u8]>,
) -> ::core::result::Result<(), $crate::cli_args::ArgError> {
match key {
$(
$key => {
if value == ::core::option::Option::Some("") {
if value == ::core::option::Option::Some(b"".as_slice()) {
$crate::cli_args::ConfigField::reset(&mut self.$field, $default);
return ::core::result::Result::Ok(());
}
$crate::cli_args::ConfigField::parse_cli(&mut self.$field, value)
$crate::cli_args::ConfigField::parse_bytes(&mut self.$field, value)
}
)*
_ => ::core::result::Result::Err($crate::cli_args::ArgError::InvalidField),
@@ -215,11 +221,11 @@ macro_rules! config_enum {
const VALID_VALUES: ::core::option::Option<&'static [&'static str]> =
::core::option::Option::Some(Self::NAMES);
fn parse_cli(
fn parse_bytes(
&mut self,
value: ::core::option::Option<&str>,
value: ::core::option::Option<&[u8]>,
) -> ::core::result::Result<(), $crate::cli_args::ArgError> {
let v = value.ok_or($crate::cli_args::ArgError::ValueRequired)?;
let v = $crate::cli_args::text_value(value)?.ok_or($crate::cli_args::ArgError::ValueRequired)?;
*self = Self::from_name(v).ok_or($crate::cli_args::ArgError::InvalidValue)?;
::core::result::Result::Ok(())
}
@@ -295,11 +301,11 @@ macro_rules! config_packed {
$crate::c_value::CValue::Packed(bits)
}
fn parse_cli(
fn parse_bytes(
&mut self,
value: ::core::option::Option<&str>,
value: ::core::option::Option<&[u8]>,
) -> ::core::result::Result<(), $crate::cli_args::ArgError> {
let v = value.ok_or($crate::cli_args::ArgError::ValueRequired)?;
let v = $crate::cli_args::text_value(value)?.ok_or($crate::cli_args::ArgError::ValueRequired)?;
let mut result = <$name as ::core::default::Default>::default();
$crate::cli_args::parse_packed_struct_with(v, Self::NAMES, |i, b| {
result.set_index(i, b);