refactor: type escaped OS strings and fix the final audit findings
Escaped config strings (ghostty_os::osbytes) kept reaching OS boundaries undecoded, and decoding was occasionally applied to plain text. The root cause was that both were plain `String`s. Now: - `EncodedOs` is a newtype (no Display/AsRef<Path>) that decodes only via to_os/to_path/to_bytes/to_wide; plain text enters via from_plain_text. OS helpers (env, home, xdg, passwd, resources dir, path expansion), config::Path, WorkingDirectory, theme/file_load/edit paths, terminal pwd, OpenUrl/Pwd actions and termio cwd use it, so the compiler forces decoding at every boundary. os::open takes &OsStr. Config output is unchanged. Fixes all rows of docs/rewrite/notes/review-rv5-codex.md (final-Z7.md): screen-file copy; regex/OSC 8 URLs no longer decoded (regression); lossless Windows WTF-8/WTF-16 for args, env and CreateProcessW; Windows resources dir/TERMINFO; color OSC request lists and X11 color lookup no longer allocate globally (C zero-allocation test extended); macOS Mach handler resumes all threads before KERN_FAILURE (hang regression) and SIGABRT minidumps go through the exception thread; plus open-config, background images, crash dir, ssh cache, exe dir/PATH, fontconfig filenames, file links, kitty TMPDIR, .hushlogin and benchmark paths. The typing also surfaced and fixed gtk-custom-css, bell audio, bash HISTFILE, OSC 52 writes and the C config getters. Test Plan: - cargo test --workspace (3376 passed) - just check-macos (both), just check-windows, just check-wasm - diff <(ghostty-rs +show-config --default --docs) \ <(ghostty +show-config --default --docs)
This commit is contained in:
1 parent
7a3f0b0f2c
commit
f7fec6f44d
92 files changed
+2967
-992
No files matched your search
@@ -5,6 +5,7 @@ use std::io::Write;
|
||||
use std::os::unix::process::CommandExt;
|
||||
|
||||
use ghostty_config::config::Config;
|
||||
use ghostty_os::osbytes::EncodedOs;
|
||||
|
||||
use crate::error::Error;
|
||||
pub use crate::options::NoOptions as Options;
|
||||
@@ -43,7 +44,7 @@ pub fn run(args: &[String]) -> Result<u8, Error> {
|
||||
|
||||
/// Pick the editor from `$VISUAL` then `$EDITOR` (empty values are skipped).
|
||||
#[must_use]
|
||||
pub fn find_editor() -> Option<String> {
|
||||
pub fn find_editor() -> Option<EncodedOs> {
|
||||
// VISUAL vs. EDITOR: https://unix.stackexchange.com/questions/4859/visual-vs-editor-what-s-the-difference
|
||||
for var in ["VISUAL", "EDITOR"] {
|
||||
if let Some(v) = ghostty_os::getenv(var) {
|
||||
@@ -76,19 +77,20 @@ fn run_inner(stderr: &mut dyn Write) -> Result<u8, Error> {
|
||||
|
||||
/// Windows branch of `run`: print the path and fail.
|
||||
#[cfg(windows)]
|
||||
fn write_windows_unsupported(stderr: &mut dyn Write, path: &str) -> Result<u8, Error> {
|
||||
fn write_windows_unsupported(stderr: &mut dyn Write, path: &EncodedOs) -> Result<u8, Error> {
|
||||
write!(
|
||||
stderr,
|
||||
"The `ghostty +edit-config` command is not supported on Windows.\n\
|
||||
Please edit the configuration file manually at the following path:\n\
|
||||
\n\
|
||||
{path}\n"
|
||||
{}\n",
|
||||
path.as_encoded()
|
||||
)?;
|
||||
Ok(1)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn exec_editor(stderr: &mut dyn Write, path: &str) -> Result<u8, Error> {
|
||||
fn exec_editor(stderr: &mut dyn Write, path: &EncodedOs) -> Result<u8, Error> {
|
||||
// Get our editor
|
||||
let Some(editor) = find_editor() else {
|
||||
// If we don't have `$EDITOR` set then we can't do anything
|
||||
@@ -107,15 +109,16 @@ fn exec_editor(stderr: &mut dyn Write, path: &str) -> Result<u8, Error> {
|
||||
);
|
||||
// Output the path using the OSC8 sequence so that it is linked.
|
||||
// (Paths are raw bytes: decode the reversible escape when writing.)
|
||||
let msg = format!("{msg}\x1b]8;;file://{path}\x1b\\{path}\x1b]8;;\x1b\\\n");
|
||||
let p = path.as_encoded();
|
||||
let msg = format!("{msg}\x1b]8;;file://{p}\x1b\\{p}\x1b]8;;\x1b\\\n");
|
||||
stderr.write_all(&ghostty_os::osbytes::config_str_to_bytes(&msg))?;
|
||||
return Ok(1);
|
||||
};
|
||||
|
||||
// Flush before exec so no output is lost.
|
||||
let _ = stderr.flush();
|
||||
let err = std::process::Command::new(ghostty_os::osbytes::config_str_to_os(&editor))
|
||||
.arg(ghostty_os::osbytes::config_str_to_os(path))
|
||||
let err = std::process::Command::new(editor.to_os())
|
||||
.arg(path.to_os())
|
||||
.exec();
|
||||
|
||||
// If we reached this point then exec failed.
|
||||
@@ -131,8 +134,10 @@ fn exec_editor(stderr: &mut dyn Write, path: &str) -> Result<u8, Error> {
|
||||
permissions, or the shell environment not being set up\n\
|
||||
correctly.\n\
|
||||
\n\
|
||||
Editor: {editor}\n\
|
||||
Path: {path}\n"
|
||||
Editor: {}\n\
|
||||
Path: {}\n",
|
||||
editor.as_encoded(),
|
||||
path.as_encoded()
|
||||
);
|
||||
stderr.write_all(&ghostty_os::osbytes::config_str_to_bytes(&msg))?;
|
||||
Ok(1)
|
||||
|
||||
Reference in new issue
Block a user