From 35e8db160d54ae330a5803711cfec6e01fb65d7d Mon Sep 17 00:00:00 2001 From: Ian Manske Date: Sat, 2 Dec 2023 17:01:08 +0000 Subject: [PATCH] Fix `get -i` ignoring errors for only the first cellpath (#11213) # Description Fixes issue #11212 where only the first cellpath supplied to `get -i` is treated as optional, and the rest of the cell paths are treated as non-optional. # Tests Added one test. --- crates/nu-command/src/filters/get.rs | 5 ++++- crates/nu-command/tests/commands/get.rs | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filters/get.rs b/crates/nu-command/src/filters/get.rs index 8b99548a06..bcfa06ce28 100644 --- a/crates/nu-command/src/filters/get.rs +++ b/crates/nu-command/src/filters/get.rs @@ -65,7 +65,7 @@ If multiple cell paths are given, this will produce a list of values."# ) -> Result { let span = call.head; let mut cell_path: CellPath = call.req(engine_state, stack, 0)?; - let rest: Vec = call.rest(engine_state, stack, 1)?; + let mut rest: Vec = call.rest(engine_state, stack, 1)?; let ignore_errors = call.has_flag("ignore-errors"); let sensitive = call.has_flag("sensitive"); let ctrlc = engine_state.ctrlc.clone(); @@ -73,6 +73,9 @@ If multiple cell paths are given, this will produce a list of values."# if ignore_errors { cell_path.make_optional(); + for path in &mut rest { + path.make_optional(); + } } if rest.is_empty() { diff --git a/crates/nu-command/tests/commands/get.rs b/crates/nu-command/tests/commands/get.rs index 9947ceffbb..4be0c76a6e 100644 --- a/crates/nu-command/tests/commands/get.rs +++ b/crates/nu-command/tests/commands/get.rs @@ -200,3 +200,10 @@ fn ignore_errors_works() { assert_eq!(actual.out, "null"); } + +#[test] +fn ignore_multiple() { + let actual = nu!(r#"[[a];[b]] | get -i c d | to nuon"#); + + assert_eq!(actual.out, "[[null], [null]]"); +}