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
7480f99d91
commit
79a7fd4f76
26 files changed
+1835
-228
No files matched your search
@@ -431,6 +431,17 @@ impl EncodedOs {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`EncodedOs::to_path`] as a syscall sees it: Zig hands paths to the
|
||||
/// OS as NUL-terminated C strings, so an interior NUL ends the path
|
||||
/// (Rust's `std::fs` would refuse the whole path instead).
|
||||
pub fn to_syscall_path(&self) -> std::io::Result<std::path::PathBuf> {
|
||||
let bytes = self.to_bytes();
|
||||
match bytes.iter().position(|&b| b == 0) {
|
||||
Some(end) => EncodedOs::from_bytes(&bytes[..end]).to_path(),
|
||||
None => self.to_path(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the decoded value starts with the given plain prefix.
|
||||
#[must_use]
|
||||
pub fn starts_with_plain(&self, prefix: &str) -> bool {
|
||||
@@ -526,6 +537,22 @@ pub fn config_str_to_path(s: &str) -> std::io::Result<std::path::PathBuf> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn syscall_path_ends_at_the_first_nul() {
|
||||
let e = EncodedOs::from_bytes(b"/a/b\0c");
|
||||
assert_eq!(
|
||||
e.to_syscall_path().unwrap(),
|
||||
std::path::PathBuf::from("/a/b")
|
||||
);
|
||||
let e = EncodedOs::from_bytes(b"/a/\xffb");
|
||||
assert_eq!(e.to_syscall_path().unwrap(), e.to_path().unwrap());
|
||||
assert_eq!(
|
||||
EncodedOs::from_bytes(b"\0x").to_syscall_path().unwrap(),
|
||||
std::path::PathBuf::new()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_paths_fail_with_bad_path_name_instead_of_replacement() {
|
||||
let error = windows_path_wide(b"C:\\bad\xff").unwrap_err();
|
||||
|
||||
Reference in new issue
Block a user