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
@@ -63,55 +63,14 @@ impl Iterator for ArgIterator {
|
||||
}
|
||||
}
|
||||
|
||||
/// Best-effort shell string splitter matching Zig's
|
||||
/// `std.process.ArgIteratorGeneral(.{})` (whitespace separated, double
|
||||
/// quotes group, backslashes only special before a double quote).
|
||||
/// Zig's `std.process.ArgIteratorGeneral(.{})`.
|
||||
fn split_general(b: &[u8]) -> Vec<EncodedOs> {
|
||||
let mut out = vec![];
|
||||
let mut i = 0;
|
||||
loop {
|
||||
// skip whitespace
|
||||
while i < b.len() && (b[i] == b' ' || b[i] == b'\t') {
|
||||
i += 1;
|
||||
}
|
||||
if i >= b.len() {
|
||||
break;
|
||||
}
|
||||
|
||||
let mut cur: Vec<u8> = vec![];
|
||||
let mut quoted = false;
|
||||
while i < b.len() {
|
||||
match b[i] {
|
||||
b' ' | b'\t' if !quoted => break,
|
||||
b'\\' => {
|
||||
let mut n = 0;
|
||||
while i < b.len() && b[i] == b'\\' {
|
||||
n += 1;
|
||||
i += 1;
|
||||
}
|
||||
if i < b.len() && b[i] == b'"' {
|
||||
cur.extend(std::iter::repeat_n(b'\\', n / 2));
|
||||
if n % 2 == 1 {
|
||||
cur.push(b'"');
|
||||
i += 1;
|
||||
}
|
||||
} else {
|
||||
cur.extend(std::iter::repeat_n(b'\\', n));
|
||||
}
|
||||
}
|
||||
b'"' => {
|
||||
quoted = !quoted;
|
||||
i += 1;
|
||||
}
|
||||
c => {
|
||||
cur.push(c);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
out.push(EncodedOs::from_bytes(&cur));
|
||||
}
|
||||
out
|
||||
ghostty_os::arg_iterator::ArgIteratorGeneral::new(
|
||||
ghostty_os::arg_iterator::Options::default(),
|
||||
b,
|
||||
)
|
||||
.map(|arg| EncodedOs::from_bytes(&arg))
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl Command {
|
||||
@@ -259,6 +218,13 @@ mod tests {
|
||||
assert_eq!(args, ["echo", "hello world", "a\"b"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_arg_iterator_shell_splits_cr_lf_tab_like_zig() {
|
||||
let v = Command::Shell(EncodedOs::from_bytes(b"bash\n-i\r\tx \"a\nb\"\0ignored"));
|
||||
let args: Vec<EncodedOs> = v.arg_iterator().collect();
|
||||
assert_eq!(args, ["bash", "-i", "x", "a\nb"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_arg_iterator_direct() {
|
||||
let v = Command::Direct(vec!["echo".into(), "hello world".into()]);
|
||||
|
||||
Reference in new issue
Block a user