Fix path join on streams (#4959)

This commit is contained in:
JT 2022-03-26 07:46:48 +13:00 committed by GitHub
parent 2252833917
commit 12b85beecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -5,8 +5,8 @@ use std::{
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::{ use nu_protocol::{
engine::Command, Example, ListStream, PipelineData, ShellError, Signature, Span, Spanned, engine::Command, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
SyntaxShape, Value, Value,
}; };
use super::PathSubcommandArguments; use super::PathSubcommandArguments;
@ -63,16 +63,15 @@ the output of 'path parse' and 'path split' subcommands."#
append: call.opt(engine_state, stack, 0)?, append: call.opt(engine_state, stack, 0)?,
}; };
let metadata = input.metadata();
match input { match input {
PipelineData::Value(val, md) => { PipelineData::Value(val, md) => {
Ok(PipelineData::Value(handle_value(val, &args, head), md)) Ok(PipelineData::Value(handle_value(val, &args, head), md))
} }
PipelineData::ListStream(stream, md) => Ok(PipelineData::ListStream( PipelineData::ListStream(..) => Ok(PipelineData::Value(
ListStream::from_stream( handle_value(input.into_value(head), &args, head),
stream.map(move |val| handle_value(val, &args, head)), metadata,
engine_state.ctrlc.clone(),
),
md,
)), )),
_ => Err(ShellError::UnsupportedInput( _ => Err(ShellError::UnsupportedInput(
"Input data is not supported by this command.".to_string(), "Input data is not supported by this command.".to_string(),

View File

@ -31,6 +31,18 @@ fn returns_path_joined_from_list() {
assert_eq!(actual.out, expected); assert_eq!(actual.out, expected);
} }
#[test]
fn drop_one_path_join() {
let actual = nu!(
cwd: "tests", pipeline(
r#"[a, b, c] | drop 1 | path join
"#
));
let expected = join_path_sep(&["a", "b"]);
assert_eq!(actual.out, expected);
}
#[test] #[test]
fn appends_slash_when_joined_with_empty_path() { fn appends_slash_when_joined_with_empty_path() {
let actual = nu!( let actual = nu!(