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_protocol::{
engine::Command, Example, ListStream, PipelineData, ShellError, Signature, Span, Spanned,
SyntaxShape, Value,
engine::Command, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
Value,
};
use super::PathSubcommandArguments;
@ -63,16 +63,15 @@ the output of 'path parse' and 'path split' subcommands."#
append: call.opt(engine_state, stack, 0)?,
};
let metadata = input.metadata();
match input {
PipelineData::Value(val, md) => {
Ok(PipelineData::Value(handle_value(val, &args, head), md))
}
PipelineData::ListStream(stream, md) => Ok(PipelineData::ListStream(
ListStream::from_stream(
stream.map(move |val| handle_value(val, &args, head)),
engine_state.ctrlc.clone(),
),
md,
PipelineData::ListStream(..) => Ok(PipelineData::Value(
handle_value(input.into_value(head), &args, head),
metadata,
)),
_ => Err(ShellError::UnsupportedInput(
"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);
}
#[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]
fn appends_slash_when_joined_with_empty_path() {
let actual = nu!(