diff --git a/crates/nu-cli/src/commands/lines.rs b/crates/nu-cli/src/commands/lines.rs index 5b6f163493..2b486a0cac 100644 --- a/crates/nu-cli/src/commands/lines.rs +++ b/crates/nu-cli/src/commands/lines.rs @@ -75,9 +75,9 @@ async fn lines(args: CommandArgs, registry: &CommandRegistry) -> Result { let mut leftover_string = leftover_string.lock(); - let st = (&*leftover_string).clone() + &st; - - let mut lines: Vec = st.lines().map(|x| x.to_string()).collect(); + let lo_lines = (&*leftover_string).lines().map(|x| x.to_string()); + let st_lines = st.lines().map(|x| x.to_string()); + let mut lines: Vec = lo_lines.chain(st_lines).collect(); leftover_string.clear(); diff --git a/crates/nu-cli/tests/commands/lines.rs b/crates/nu-cli/tests/commands/lines.rs index 6f394fad87..efb77ea77b 100644 --- a/crates/nu-cli/tests/commands/lines.rs +++ b/crates/nu-cli/tests/commands/lines.rs @@ -34,3 +34,18 @@ fn lines_proper_buffering() { assert_eq!(actual.out, "[8194,4]"); } + +#[test] +fn lines_multi_value_split() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + open sample-simple.json + | get first second + | lines + | count + "# + )); + + assert_eq!(actual.out, "6"); +} diff --git a/tests/fixtures/formats/sample-simple.json b/tests/fixtures/formats/sample-simple.json new file mode 100644 index 0000000000..7986b6e546 --- /dev/null +++ b/tests/fixtures/formats/sample-simple.json @@ -0,0 +1,4 @@ +{ + "first": "first", + "second": "this\nshould\nbe\nseparate\nlines" +} \ No newline at end of file