mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Fix panic when assigning value to $env (#7894)
This commit is contained in:
parent
3c6b10c6b2
commit
2a39332d51
3 changed files with 25 additions and 0 deletions
|
@ -467,6 +467,12 @@ pub fn eval_expression(
|
||||||
|
|
||||||
lhs.upsert_data_at_cell_path(&cell_path.tail, rhs)?;
|
lhs.upsert_data_at_cell_path(&cell_path.tail, rhs)?;
|
||||||
if is_env {
|
if is_env {
|
||||||
|
if cell_path.tail.is_empty() {
|
||||||
|
return Err(ShellError::CannotReplaceEnv(
|
||||||
|
cell_path.head.span,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// The special $env treatment: for something like $env.config.history.max_size = 2000,
|
// The special $env treatment: for something like $env.config.history.max_size = 2000,
|
||||||
// get $env.config (or whichever one it is) AFTER the above mutation, and set it
|
// get $env.config (or whichever one it is) AFTER the above mutation, and set it
|
||||||
// as the "config" environment variable.
|
// as the "config" environment variable.
|
||||||
|
|
|
@ -365,6 +365,20 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||||
)]
|
)]
|
||||||
AutomaticEnvVarSetManually(String, #[label("cannot set '{0}' manually")] Span),
|
AutomaticEnvVarSetManually(String, #[label("cannot set '{0}' manually")] Span),
|
||||||
|
|
||||||
|
/// It is not possible to replace the entire environment at once
|
||||||
|
///
|
||||||
|
/// ## Resolution
|
||||||
|
///
|
||||||
|
/// Setting the entire environment is not allowed. Change environment variables individually
|
||||||
|
/// instead.
|
||||||
|
#[error("Cannot replace environment.")]
|
||||||
|
#[diagnostic(
|
||||||
|
code(nu::shell::cannot_replace_env),
|
||||||
|
url(docsrs),
|
||||||
|
help(r#"Assigning a value to $env is not allowed."#)
|
||||||
|
)]
|
||||||
|
CannotReplaceEnv(#[label("setting $env not allowed")] Span),
|
||||||
|
|
||||||
/// Division by zero is not a thing.
|
/// Division by zero is not a thing.
|
||||||
///
|
///
|
||||||
/// ## Resolution
|
/// ## Resolution
|
||||||
|
|
|
@ -371,3 +371,8 @@ fn range_right_exclusive() -> TestResult {
|
||||||
fn assignment_to_in_var_no_panic() -> TestResult {
|
fn assignment_to_in_var_no_panic() -> TestResult {
|
||||||
fail_test(r#"$in = 3"#, "needs to be a mutable variable")
|
fail_test(r#"$in = 3"#, "needs to be a mutable variable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn assignment_to_env_no_panic() -> TestResult {
|
||||||
|
fail_test(r#"$env = 3"#, "cannot_replace_env")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue