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
This commit is contained in:
Access 2022-11-21 09:32:15 +08:00 committed by GitHub
parent d9d6cea5a9
commit 899383c30c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -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())

View file

@ -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#"
`<!DOCTYPE html><html><body><a href='http://example.org/'>Example</a></body></html>` | save save_test_7/temp.html
"#,
);
let actual = file_contents(expected_file);
assert_eq!(
actual,
r#"<!DOCTYPE html><html><body><a href='http://example.org/'>Example</a></body></html>"#
)
})
}