From aef88aa03ef710b0cce09aadaa059b967213283b Mon Sep 17 00:00:00 2001 From: Amirhossein Akhlaghpour <51247512+Mehrbod2002@users.noreply.github.com> Date: Mon, 6 Feb 2023 02:10:46 +0330 Subject: [PATCH] Load env pwd (#7963) # Description Fixes #7940 avoid `load-env` to change PWD # User-Facing Changes `{"PWD": whatever} | load-env` now fails --- crates/nu-command/src/env/load_env.rs | 5 +---- tests/shell/environment/env.rs | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/env/load_env.rs b/crates/nu-command/src/env/load_env.rs index 9c9dff82a8..4040a5b1dc 100644 --- a/crates/nu-command/src/env/load_env.rs +++ b/crates/nu-command/src/env/load_env.rs @@ -47,10 +47,7 @@ impl Command for LoadEnv { } if env_var == "PWD" { - let cwd = current_dir(engine_state, stack)?; - let rhs = rhs.as_string()?; - let rhs = nu_path::expand_path_with(rhs, cwd); - stack.add_env_var(env_var, Value::string(rhs.to_string_lossy(), call.head)); + return Err(ShellError::AutomaticEnvVarSetManually(env_var, call.head)); } else { stack.add_env_var(env_var, rhs); } diff --git a/tests/shell/environment/env.rs b/tests/shell/environment/env.rs index 8bf5ee854b..0cad3caed2 100644 --- a/tests/shell/environment/env.rs +++ b/tests/shell/environment/env.rs @@ -99,6 +99,13 @@ fn load_env_file_pwd_env_var_fails() { assert!(actual.err.contains("automatic_env_var_set_manually")); } +#[test] +fn load_env_pwd_env_var_fails() { + let actual = nu!(cwd: ".", r#"load-env { PWD : 'foo' }"#); + + assert!(actual.err.contains("automatic_env_var_set_manually")); +} + // FIXME: for some reason Nu is attempting to execute foo in `let-env FOO = foo` #[ignore] #[test]