Skip to content

Commit c13a0eb

Browse files
committed
fix: support command environment variables to contain equal signs
1 parent 4e3efc5 commit c13a0eb

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/process.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,11 @@ impl Cmd {
329329

330330
let arg_str = arg.to_string_lossy().to_string();
331331
if arg_str != IGNORE_CMD && !self.args.iter().any(|cmd| *cmd != IGNORE_CMD) {
332-
let v: Vec<&str> = arg_str.split('=').collect();
333-
if v.len() == 2 && v[0].chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
334-
self.vars.insert(v[0].into(), v[1].into());
335-
return self;
332+
if let Some((key, value)) = arg_str.split_once('=') {
333+
if key.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
334+
self.vars.insert(key.into(), value.into());
335+
return self;
336+
}
336337
}
337338
self.in_cmd_map = CMD_MAP.lock().unwrap().contains_key(arg);
338339
}

tests/test_macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,8 @@ fn test_empty_arg() {
263263
let opt = "";
264264
assert!(run_cmd!(ls $opt).is_ok());
265265
}
266+
267+
#[test]
268+
fn test_env_var_with_equal_sign() {
269+
assert!(run_cmd!(A="-c B=c" echo).is_ok());
270+
}

0 commit comments

Comments
 (0)