From 75556f6c5f73cd40e3df04cab494ce0d278aa81e Mon Sep 17 00:00:00 2001 From: Anonymity <2254228017@qq.com> Date: Sat, 12 Nov 2022 00:45:51 +0800 Subject: [PATCH] fix(#7097): let-env should not be able to set PWD (#7100) --- crates/nu-command/src/env/let_env.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/crates/nu-command/src/env/let_env.rs b/crates/nu-command/src/env/let_env.rs index ae2d5fc6c2..bf7a6fff00 100644 --- a/crates/nu-command/src/env/let_env.rs +++ b/crates/nu-command/src/env/let_env.rs @@ -1,4 +1,4 @@ -use nu_engine::{current_dir, eval_expression_with_input, CallExt}; +use nu_engine::{eval_expression_with_input, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ @@ -49,24 +49,11 @@ impl Command for LetEnv { .0 .into_value(call.head); - if env_var.item == "FILE_PWD" { + if env_var.item == "FILE_PWD" || env_var.item == "PWD" { return Err(ShellError::AutomaticEnvVarSetManually( env_var.item, env_var.span, )); - } - - if env_var.item == "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.item, - Value::String { - val: rhs.to_string_lossy().to_string(), - span: call.head, - }, - ); } else { stack.add_env_var(env_var.item, rhs); }