fix(#7097): let-env should not be able to set PWD (#7100)

This commit is contained in:
Anonymity 2022-11-12 00:45:51 +08:00 committed by GitHub
parent b650d1ef79
commit 75556f6c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
@ -49,24 +49,11 @@ impl Command for LetEnv {
.0 .0
.into_value(call.head); .into_value(call.head);
if env_var.item == "FILE_PWD" { if env_var.item == "FILE_PWD" || env_var.item == "PWD" {
return Err(ShellError::AutomaticEnvVarSetManually( return Err(ShellError::AutomaticEnvVarSetManually(
env_var.item, env_var.item,
env_var.span, 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 { } else {
stack.add_env_var(env_var.item, rhs); stack.add_env_var(env_var.item, rhs);
} }