Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Link the C runtime statically so release executables do not depend on
# VCRUNTIME140.dll (VC++ Redistributable), which clean Windows installs lack.

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

[target.aarch64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: Test

on:
Expand All @@ -24,13 +24,13 @@
persist-credentials: false

- name: Install Rust
uses: dtolnay/rust-toolchain@1482605baf5e54c3a4a81144c8575711b97477ef # master
uses: dtolnay/rust-toolchain@02cb101ec7c40f2c49e1d9714d64511d8e1b74de # master
with:
toolchain: 1.98
components: clippy

- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@82a92a6e3519e677e0ddc7726a767aea594a9a53 # v2
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
with:
key: test

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified bin/wftui
Binary file not shown.
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "common"
version = "0.0.3"
version = "0.0.4"
edition = "2024"
rust-version = "1.98"
publish = false
Expand Down
78 changes: 50 additions & 28 deletions common/src/osc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,55 @@ mod tests {
/// Control characters in user-sourced titles/URLs must be stripped at
/// the OSC boundary (#649): a BEL/ESC in a thread title could otherwise
/// terminate or inject sequences inside the terminal itself.
/// Runs `f` with the multiplexer env (TMUX/STY/TERM) set as given, under
/// ENV_LOCK, restoring the previous values afterwards — even if `f`
/// panics — so tests asserting on exact sequences don't depend on
/// whether `cargo test` itself runs inside tmux or screen.
fn with_mux_env<R>(
tmux: Option<&str>,
sty: Option<&str>,
term: Option<&str>,
f: impl FnOnce() -> R,
) -> R {
struct Restore([(&'static str, Option<std::ffi::OsString>); 3]);
impl Drop for Restore {
fn drop(&mut self) {
for (key, prev) in &self.0 {
// SAFETY: env mutation happens only under ENV_LOCK.
unsafe {
match prev {
Some(v) => std::env::set_var(key, v),
None => std::env::remove_var(key),
}
}
}
}
}

let _g = crate::config::ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let wanted = [("TMUX", tmux), ("STY", sty), ("TERM", term)];
let _restore = Restore(wanted.map(|(key, _)| (key, std::env::var_os(key))));
for (key, value) in wanted {
// SAFETY: env mutation happens only under ENV_LOCK.
unsafe {
match value {
Some(v) => std::env::set_var(key, v),
None => std::env::remove_var(key),
}
}
}
f()
}

#[test]
fn titles_and_hrefs_carry_no_control_characters() {
let t = set_title("Windows \u{1b}]0;pwned\u{7} Forum tabs");
// Outside any multiplexer, so both emit their bare OSC sequences.
let (t, h) = with_mux_env(None, None, Some("xterm-256color"), || {
(
set_title("Windows \u{1b}]0;pwned\u{7} Forum tabs"),
hyperlink("https://x.test/a\u{7}b", "click\u{1b}me"),
)
});
// Exactly the framing escapes remain: OSC open, BEL terminator; the
// injected sequences' control bytes are gone, leaving plain text.
assert!(t.starts_with("\x1b]0;"), "{t:?}");
Expand All @@ -365,7 +411,6 @@ mod tests {
// text ("Windows ]0;pwned Forum tabs") is inert, printable text.
assert!(inner.starts_with("Windows ") && inner.ends_with("Forum tabs"), "{t:?}");

let h = hyperlink("https://x.test/a\u{7}b", "click\u{1b}me");
assert!(!h.contains('\u{7}'), "{h:?}");
let payload = h.trim_start_matches("\x1b]8;;").trim_end_matches("\x1b]8;;\x1b\\");
assert!(payload.starts_with("https://x.test/ab\x1b\\clickme"), "{h:?}");
Expand Down Expand Up @@ -451,34 +496,11 @@ mod tests {
/// alongside the screen-wrapped DCS (which real screen needs).
#[test]
fn screen_like_term_over_ssh_dual_delivers_raw_plus_dcs() {
let _g = crate::config::ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let prev_tmux = std::env::var_os("TMUX");
let prev_sty = std::env::var_os("STY");
let prev_term = std::env::var_os("TERM");
unsafe {
std::env::remove_var("TMUX");
std::env::remove_var("STY");
std::env::set_var("TERM", "screen-256color");
}

let out = set_clipboard("https://windowsforum.com/x");
let out = with_mux_env(None, None, Some("screen-256color"), || {
set_clipboard("https://windowsforum.com/x")
});
assert!(out.starts_with("\x1b]52;c;"), "missing raw OSC 52: {out:?}");
assert!(out.contains("\x1bP"), "missing screen-wrapped DCS: {out:?}");

unsafe {
match prev_tmux {
Some(v) => std::env::set_var("TMUX", v),
None => std::env::remove_var("TMUX"),
}
match prev_sty {
Some(v) => std::env::set_var("STY", v),
None => std::env::remove_var("STY"),
}
match prev_term {
Some(v) => std::env::set_var("TERM", v),
None => std::env::remove_var("TERM"),
}
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion wftui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wftui"
version = "0.0.3"
version = "0.0.4"
Comment thread
faratech marked this conversation as resolved.
Resolved
edition = "2024"
rust-version = "1.98"
publish = false
Expand Down
Loading