fix(config): match Zig's numeric grammar, NUL handling and diagnostics
Resolves the 6 differential gap groups in docs/rewrite/notes/review- rv9-codex.md (details in final-Z11.md): - ghostty_os::zig_fmt ports std.fmt.parseInt/parseUnsigned/parseFloat (underscores, 0x/0o/0b prefixes, hex floats, inf/nan) with the Zig std tests and replaces every int/float parse in config, keybind parameters, ssh-cache and desktop detection. - Interior NUL no longer panics in font names and ends C strings like Zig's backing bytes (fontconfig, C config getters, title actions, clipboard callback, relative paths, config-file, shaders, background image, GTK CSS). - GTK new-window arguments are trimmed of ASCII whitespace only. - Command tokenization uses a port of std.process.ArgIteratorGeneral (incl. CR/LF separators) with its std tests. - UTF-8 validation happens where Zig's field parsers do it, so error kinds match (metric modifiers, quick-terminal size, link, ...). A scripted differential run of 202 fields x ~220 hostile/valid values against /usr/bin/ghostty (+validate-config and +show-config: exit code, stdout, stderr) now has zero mismatches besides build-specific defaults (theme resources path, auto-update-channel, gtk-opengl-debug); it also surfaced and fixed background-blur failure state, NaN formatting and NaN/-0 finalize clamps. Regression tests: ghostty-config/tests/ zig_parity.rs. Test Plan: - cargo test --workspace --no-fail-fast (3456 passed, exit 0) - just check-macos (both), just check-windows, just check-wasm
This commit is contained in:
1 parent
61e7a680ac
commit
a57ff41d34
26 files changed
+1835
-228
No files matched your search
@@ -162,6 +162,43 @@ mod fc_impl {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[cfg(font_fontconfig)]
|
||||
#[test]
|
||||
fn interior_nul_in_font_names_ends_the_c_string() {
|
||||
use ghostty_config::config::Config;
|
||||
use ghostty_os::osbytes::os_bytes;
|
||||
|
||||
use crate::fontconfig::Property;
|
||||
let mut config = Config::default();
|
||||
config
|
||||
.parse_field_bytes("font-family", Some(b"monospace\0suffix"))
|
||||
.unwrap();
|
||||
config
|
||||
.parse_field_bytes("font-style", Some(b"Regular\0suffix"))
|
||||
.unwrap();
|
||||
config
|
||||
.parse_field_bytes("font-codepoint-map", Some(b"U+0041=Fam\0ily"))
|
||||
.unwrap();
|
||||
let pat = to_fc_pattern(&Descriptor {
|
||||
family: Some(config.font_family.list[0].clone()),
|
||||
style: config.font_style.name_value().cloned(),
|
||||
..Descriptor::default()
|
||||
});
|
||||
assert_eq!(
|
||||
os_bytes(&pat.get_os_string(Property::Family, 0).unwrap()),
|
||||
b"monospace"
|
||||
);
|
||||
assert_eq!(
|
||||
os_bytes(&pat.get_os_string(Property::Style, 0).unwrap()),
|
||||
b"Regular"
|
||||
);
|
||||
let pat = to_fc_pattern(&config.font_codepoint_map.map.list[0].descriptor);
|
||||
assert_eq!(
|
||||
os_bytes(&pat.get_os_string(Property::Family, 0).unwrap()),
|
||||
b"Fam"
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(font_fontconfig)]
|
||||
#[test]
|
||||
fn configured_font_names_reach_fontconfig_as_original_bytes() {
|
||||
|
||||
@@ -189,8 +189,10 @@ impl Pattern {
|
||||
self.add_string_bytes(prop, v.as_bytes())
|
||||
}
|
||||
|
||||
/// [`Pattern::add_string`] for arbitrary bytes (file names).
|
||||
/// [`Pattern::add_string`] for arbitrary bytes (file names). Like Zig's
|
||||
/// sentinel-terminated C string handoff, the value ends at the first NUL.
|
||||
pub fn add_string_bytes(&mut self, prop: Property, v: &[u8]) -> bool {
|
||||
let v = v.split(|&b| b == 0).next().unwrap_or(v);
|
||||
let Ok(c) = CString::new(v) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user