From 72c27bd09537a655fa43008b3365cbcc91ce3bae Mon Sep 17 00:00:00 2001 From: nibon7 Date: Tue, 26 Jul 2022 07:41:30 +0800 Subject: [PATCH] Fix PipelineData::print when `table` is overridden (#6129) * Fix PipelineData::print when `table` is overridden Fixes #6113 Signed-off-by: nibon7 * don't use deprecated `is_custom_command` Signed-off-by: nibon7 * add test Signed-off-by: nibon7 --- crates/nu-protocol/src/pipeline_data.rs | 12 ++++++------ src/tests/test_custom_commands.rs | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/nu-protocol/src/pipeline_data.rs b/crates/nu-protocol/src/pipeline_data.rs index 6b966d1447..898c735326 100644 --- a/crates/nu-protocol/src/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline_data.rs @@ -460,12 +460,12 @@ impl PipelineData { match engine_state.find_decl("table".as_bytes(), &[]) { Some(decl_id) => { - let table = engine_state.get_decl(decl_id).run( - engine_state, - stack, - &Call::new(Span::new(0, 0)), - self, - )?; + let command = engine_state.get_decl(decl_id); + if command.get_block_id().is_some() { + return self.write_all_and_flush(engine_state, config, no_newline, to_stderr); + } + + let table = command.run(engine_state, stack, &Call::new(Span::new(0, 0)), self)?; table.write_all_and_flush(engine_state, config, no_newline, to_stderr)?; } diff --git a/src/tests/test_custom_commands.rs b/src/tests/test_custom_commands.rs index 67d3cd274e..2c668eb15f 100644 --- a/src/tests/test_custom_commands.rs +++ b/src/tests/test_custom_commands.rs @@ -130,3 +130,8 @@ fn help_not_present_in_extern() -> TestResult { "Usage:\n > git fetch", ) } + +#[test] +fn override_table() -> TestResult { + run_test(r#"def table [] { "hi" }; table"#, "hi") +}