Skip to content

Commit 6572e89

Browse files
committed
Skip empty arguments
fix #63
1 parent 186b0b9 commit 6572e89

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/process.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,22 @@ impl Cmd {
321321
where
322322
O: AsRef<OsStr>,
323323
{
324-
let arg_str = arg.as_ref().to_string_lossy().to_string();
324+
let arg = arg.as_ref();
325+
if arg.is_empty() {
326+
// Skip empty arguments
327+
return self;
328+
}
329+
330+
let arg_str = arg.to_string_lossy().to_string();
325331
if arg_str != IGNORE_CMD && !self.args.iter().any(|cmd| *cmd != IGNORE_CMD) {
326332
let v: Vec<&str> = arg_str.split('=').collect();
327333
if v.len() == 2 && v[0].chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
328334
self.vars.insert(v[0].into(), v[1].into());
329335
return self;
330336
}
331-
self.in_cmd_map = CMD_MAP.lock().unwrap().contains_key(arg.as_ref());
337+
self.in_cmd_map = CMD_MAP.lock().unwrap().contains_key(arg);
332338
}
333-
self.args.push(arg.as_ref().to_os_string());
339+
self.args.push(arg.to_os_string());
334340
self
335341
}
336342

tests/test_macros.rs

+6
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,9 @@ fn test_path_as_var() {
249249
let dir2 = std::path::PathBuf::from("/");
250250
assert_eq!("/", run_fun!(cd $dir2; pwd).unwrap());
251251
}
252+
253+
#[test]
254+
fn test_empty_arg() {
255+
let opt = "";
256+
assert!(run_cmd!(ls $opt).is_ok());
257+
}

0 commit comments

Comments
 (0)