diff --git a/crates/nu-engine/src/evaluate/evaluator.rs b/crates/nu-engine/src/evaluate/evaluator.rs index fea3bd9271..1231c1a714 100644 --- a/crates/nu-engine/src/evaluate/evaluator.rs +++ b/crates/nu-engine/src/evaluate/evaluator.rs @@ -200,7 +200,11 @@ pub fn evaluate_baseline_expr( }; } - Ok(item.value.into_value(tag)) + if path.tail.is_empty() { + Ok(item) + } else { + Ok(item.value.into_value(tag)) + } } Expression::Boolean(_boolean) => Ok(UntaggedValue::boolean(*_boolean).into_value(tag)), Expression::Garbage => unimplemented!(), @@ -289,7 +293,10 @@ fn evaluate_invocation(block: &hir::Block, ctx: &EvaluationContext) -> Result 1 => Ok(UntaggedValue::Table(output).into_value(Tag::unknown())), + x if x > 1 => { + let tag = output[0].tag.clone(); + Ok(UntaggedValue::Table(output).into_value(tag)) + } 1 => Ok(output[0].clone()), _ => Ok(UntaggedValue::nothing().into_value(Tag::unknown())), } diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index dfc8a022ed..ce370d9347 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -61,6 +61,60 @@ fn treats_dot_dot_as_path_not_range() { }) } +#[test] +fn tags_dont_persist_through_column_path() { + Playground::setup("dot_dot_dir", |dirs, sandbox| { + sandbox.with_files(vec![FileWithContentToBeTrimmed( + "nu_times.csv", + r#" + name,rusty_luck,origin + Jason,1,Canada + "#, + )]); + + let actual = nu!( + cwd: dirs.test(), pipeline( + r#" + mkdir temp; + cd temp; + let x = (open ../nu_times.csv).name; + $x | tags | get anchor | autoview; + rmdir temp + "# + )); + + // chop will remove the last escaped double quote from \"Estados Unidos\" + assert!(actual.err.contains("isn't a column")); + }) +} + +#[test] +fn tags_persist_through_vars() { + Playground::setup("dot_dot_dir", |dirs, sandbox| { + sandbox.with_files(vec![FileWithContentToBeTrimmed( + "nu_times.csv", + r#" + name,rusty_luck,origin + Jason,1,Canada + "#, + )]); + + let actual = nu!( + cwd: dirs.test(), pipeline( + r#" + mkdir temp; + cd temp; + let x = (open ../nu_times.csv); + $x | tags | get anchor | autoview; + rmdir temp + "# + )); + + // chop will remove the last escaped double quote from \"Estados Unidos\" + assert!(actual.out.contains("nu_times.csv")); + }) +} + #[test] fn invocation_properly_redirects() { let actual = nu!(