From 899383c30c03fb9274e7cd862d4ec5bd36af6590 Mon Sep 17 00:00:00 2001 From: Access Date: Mon, 21 Nov 2022 09:32:15 +0800 Subject: [PATCH] feat: Use Raw Text to save if pipeline data is ExternalStream (#7082) if not value type or Value as String in nushell, save will use raw type --- crates/nu-command/src/filesystem/save.rs | 5 +++++ crates/nu-command/tests/commands/save.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/crates/nu-command/src/filesystem/save.rs b/crates/nu-command/src/filesystem/save.rs index acb2299303..f5f86cbfc6 100644 --- a/crates/nu-command/src/filesystem/save.rs +++ b/crates/nu-command/src/filesystem/save.rs @@ -121,6 +121,11 @@ impl Command for Save { let ext = if raw { None + // if is extern stream , in other words , not value + } else if let PipelineData::ExternalStream { .. } = input { + None + } else if let PipelineData::Value(Value::String { .. }, ..) = input { + None } else { path.extension() .map(|name| name.to_string_lossy().to_string()) diff --git a/crates/nu-command/tests/commands/save.rs b/crates/nu-command/tests/commands/save.rs index c70eb0ea75..b8a9e166de 100644 --- a/crates/nu-command/tests/commands/save.rs +++ b/crates/nu-command/tests/commands/save.rs @@ -130,3 +130,22 @@ fn save_stderr_and_stdout_to_diff_file() { assert!(!actual.contains("bar")); }) } + +#[test] +fn save_string_and_stream_as_raw() { + Playground::setup("save_test_7", |dirs, sandbox| { + sandbox.with_files(vec![]); + let expected_file = dirs.test().join("temp.html"); + nu!( + cwd: dirs.root(), + r#" + `Example` | save save_test_7/temp.html + "#, + ); + let actual = file_contents(expected_file); + assert_eq!( + actual, + r#"Example"# + ) + }) +}