Skip to content

Commit cf49f60

Browse files
phanenLoricAndre
andauthored
fix(windows): raw_arg to avoid escape issue (#1061)
* fix(windows): raw_arg to avoid escape issue * chore: tweaks --------- Co-authored-by: Loric ANDRE <loric.andre@pm.me>
1 parent bf63404 commit cf49f60

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
//! ).unwrap();
2121
//! ```
2222
23-
#![warn(missing_docs)]
24-
#![warn(clippy::pedantic)]
25-
#![warn(clippy::incompatible_msrv)]
26-
#![allow(clippy::default_trait_access, clippy::struct_excessive_bools)]
23+
#![warn(clippy::pedantic, missing_docs, clippy::incompatible_msrv)]
24+
#![allow(
25+
clippy::default_trait_access,
26+
clippy::struct_excessive_bools,
27+
clippy::collapsible_match
28+
)]
2729

2830
#[macro_use]
2931
extern crate log;
@@ -91,8 +93,13 @@ fn shell_cmd(cmd: &str) -> Command {
9193
}
9294
#[cfg(windows)]
9395
fn shell_cmd(cmd: &str) -> Command {
96+
use std::os::windows::process::CommandExt as _;
97+
// `cmd.exe` does not parse its command line using MSVC rules, so the default
98+
// `Command::arg` escaping (quoting/backslash-escaping) corrupts shell
99+
// metacharacters like `|`, `&`, `>` and embedded quotes. Pass the command
100+
// string verbatim via `raw_arg` so cmd.exe sees exactly what the user wrote.
94101
let mut c = Command::new("cmd");
95-
c.arg("/c").arg(cmd);
102+
c.arg("/c").raw_arg(cmd);
96103
c
97104
}
98105

src/popup/zellij.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ fn middle_coord(size: Size, var: &str) -> Size {
1818
Size::Percent(p) => Size::Percent(100u16.saturating_sub(p) / 2),
1919
Size::Fixed(cells) => Size::Fixed(
2020
std::env::var(var)
21-
.map(|s| s.parse().unwrap_or(80))
22-
.unwrap_or(80u16)
21+
.map_or(80u16, |s| s.parse().unwrap_or(80))
2322
.saturating_sub(cells)
2423
/ 2,
2524
),
@@ -32,8 +31,7 @@ fn align_end_coord(size: Size, var: &str) -> Size {
3231
Size::Percent(p) => Size::Percent(100 - p),
3332
Size::Fixed(cols) => Size::Fixed(
3433
std::env::var(var)
35-
.map(|s| s.parse().unwrap_or(80))
36-
.unwrap_or(80u16)
34+
.map_or(80u16, |s| s.parse().unwrap_or(80))
3735
.saturating_sub(cols),
3836
),
3937
Size::Neg(cells) => Size::Fixed(cells),

src/skim_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ impl Display for dyn SkimItem {
9393
}
9494
impl Debug for dyn SkimItem {
9595
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96-
f.write_fmt(format_args!("SkimItem {{ text: {} }}", self.text(),))
96+
f.write_fmt(format_args!("SkimItem {{ text: {} }}", self.text()))
9797
}
9898
}

0 commit comments

Comments
 (0)