From 8c13fd6dc7624d7289e758d6aaa1109920d85564 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Wed, 8 Nov 2023 20:52:54 +0100 Subject: [PATCH] fix: environment activation for windows --- crates/rattler_shell/src/shell/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/rattler_shell/src/shell/mod.rs b/crates/rattler_shell/src/shell/mod.rs index dae98c175..312a1a6d6 100644 --- a/crates/rattler_shell/src/shell/mod.rs +++ b/crates/rattler_shell/src/shell/mod.rs @@ -120,7 +120,11 @@ pub trait Shell { /// Parses environment variables emitted by the `Shell::env` command. fn parse_env<'i>(&self, env: &'i str) -> HashMap<&'i str, &'i str> { env.lines() - .filter_map(|line| line.split_once('=')) + .filter_map(|line| { + line.split_once('=') + // Trim " as CmdExe could add this to its variables. + .map(|(key, value)| (key, value.trim_matches('"'))) + }) .collect() } } @@ -784,4 +788,18 @@ mod tests { ); assert!(script.contents.contains("/foo;/bar")); } + + #[test] + fn test_parse_env() { + let script = ShellScript::new(CmdExe, Platform::Win64); + let input = "VAR1=\"value1\"\nNUM=1\nNUM2=\"2\""; + let parsed_env = script.shell.parse_env(input); + + let expected_env: HashMap<&str, &str> = + vec![("VAR1", "value1"), ("NUM", "1"), ("NUM2", "2")] + .into_iter() + .collect(); + + assert_eq!(parsed_env, expected_env); + } }