From 25a776c36b2af490deac7952e991b608b5f00d40 Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Sat, 25 Sep 2021 16:45:02 +0100 Subject: [PATCH] trim lines in command --- crates/nu-command/src/build_string.rs | 13 ++++++------- crates/nu-command/src/lines.rs | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/nu-command/src/build_string.rs b/crates/nu-command/src/build_string.rs index 90516cde07..a0b64b9f3d 100644 --- a/crates/nu-command/src/build_string.rs +++ b/crates/nu-command/src/build_string.rs @@ -1,7 +1,7 @@ use nu_engine::eval_expression; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EvaluationContext}; -use nu_protocol::{Signature, SyntaxShape, Value}; +use nu_protocol::{ShellError, Signature, SyntaxShape, Value}; pub struct BuildString; @@ -24,13 +24,12 @@ impl Command for BuildString { call: &Call, _input: Value, ) -> Result { - let mut output = vec![]; + let output = call + .positional + .iter() + .map(|expr| eval_expression(context, expr).map(|val| val.into_string())) + .collect::, ShellError>>()?; - for expr in &call.positional { - let val = eval_expression(context, expr)?; - - output.push(val.into_string()); - } Ok(Value::String { val: output.join(""), span: call.head, diff --git a/crates/nu-command/src/lines.rs b/crates/nu-command/src/lines.rs index f3517c8e65..74333ff3ef 100644 --- a/crates/nu-command/src/lines.rs +++ b/crates/nu-command/src/lines.rs @@ -62,7 +62,7 @@ impl Command for Lines { .filter_map(|s| { if !s.is_empty() { Some(Value::String { - val: s.into(), + val: s.trim().into(), span, }) } else {