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
99 lines
2.6 KiB
Rust
99 lines
2.6 KiB
Rust
//! CodepointMap is a map of codepoints to a discovery descriptor of a font
|
|
//! to use for that codepoint. If the descriptor doesn't return any matching
|
|
//! font, the codepoint is rendered using the default font.
|
|
//! Port of `font/CodepointMap.zig`.
|
|
|
|
//!
|
|
//! The canonical definition lives in `ghostty-config` (the `font-codepoint-map`
|
|
//! option parses straight into it); it is re-exported here.
|
|
|
|
pub use ghostty_config::font_types::{CodepointMap, CodepointMapEntry as Entry};
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use ghostty_config::font_types::Descriptor;
|
|
|
|
use super::*;
|
|
|
|
fn desc(family: &str) -> Descriptor {
|
|
Descriptor {
|
|
family: Some(family.into()),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
fn entry(a: u32, b: u32, family: &str) -> Entry {
|
|
Entry {
|
|
range: [a, b],
|
|
descriptor: desc(family),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn codepointmap() {
|
|
let mut m = CodepointMap::default();
|
|
|
|
// Exact range
|
|
assert!(m.get(1).is_none());
|
|
m.add(entry(1, 1, "A"));
|
|
assert_eq!(
|
|
"A",
|
|
m.get(1)
|
|
.unwrap()
|
|
.family
|
|
.as_ref()
|
|
.map(ghostty_os::osbytes::EncodedOs::as_encoded)
|
|
.unwrap()
|
|
);
|
|
|
|
// Later entry takes priority
|
|
m.add(entry(1, 2, "B"));
|
|
assert_eq!(
|
|
"B",
|
|
m.get(1)
|
|
.unwrap()
|
|
.family
|
|
.as_ref()
|
|
.map(ghostty_os::osbytes::EncodedOs::as_encoded)
|
|
.unwrap()
|
|
);
|
|
|
|
// Non-matching
|
|
assert!(m.get(0).is_none());
|
|
assert!(m.get(3).is_none());
|
|
|
|
m.add(entry(3, 4, "C"));
|
|
m.add(entry(5, 6, "D"));
|
|
assert_eq!(
|
|
"C",
|
|
m.get(3)
|
|
.unwrap()
|
|
.family
|
|
.as_ref()
|
|
.map(ghostty_os::osbytes::EncodedOs::as_encoded)
|
|
.unwrap()
|
|
);
|
|
assert_eq!(
|
|
"B",
|
|
m.get(1)
|
|
.unwrap()
|
|
.family
|
|
.as_ref()
|
|
.map(ghostty_os::osbytes::EncodedOs::as_encoded)
|
|
.unwrap()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn hashcode_depends_on_contents() {
|
|
let mut a = CodepointMap::default();
|
|
let mut b = CodepointMap::default();
|
|
assert_eq!(a.hashcode(), b.hashcode());
|
|
a.add(entry(1, 2, "A"));
|
|
assert_ne!(a.hashcode(), b.hashcode());
|
|
b.add(entry(1, 2, "A"));
|
|
assert_eq!(a.hashcode(), b.hashcode());
|
|
b.add(entry(3, 3, "B"));
|
|
assert_ne!(a.hashcode(), b.hashcode());
|
|
}
|
|
}
|