fix(cell-path): special case $env

This commit is contained in:
Bahex 2025-05-04 10:35:22 +03:00
parent e10538bd8d
commit e48ad0d531
2 changed files with 15 additions and 4 deletions

View File

@ -592,8 +592,11 @@ impl Eval for EvalRuntime {
// Retrieve the updated environment value.
lhs.upsert_data_at_cell_path(&cell_path.tail, rhs)?;
let value =
lhs.follow_cell_path(&[cell_path.tail[0].clone()], true)?;
let value = lhs.follow_cell_path(&[{
let mut pm = cell_path.tail[0].clone();
pm.make_insensitive();
pm
}])?;
// Reject attempts to set automatic environment variables.
if is_automatic_env_var(&original_key) {

View File

@ -43,8 +43,16 @@ pub trait Eval {
// Cell paths are usually case-sensitive, but we give $env
// special treatment.
let insensitive = cell_path.head.expr == Expr::Var(ENV_VARIABLE_ID);
value.follow_cell_path(&cell_path.tail, insensitive).map(Cow::into_owned)
let tail = if cell_path.head.expr == Expr::Var(ENV_VARIABLE_ID) {
let mut tail = cell_path.tail.clone();
if let Some(pm) = tail.first_mut() {
pm.make_insensitive();
}
Cow::Owned(tail)
} else {
Cow::Borrowed(&cell_path.tail)
};
value.follow_cell_path(&tail).map(Cow::into_owned)
}
Expr::DateTime(dt) => Ok(Value::date(*dt, expr_span)),
Expr::List(list) => {