diff --git a/crates/nu-command/src/strings/split/row.rs b/crates/nu-command/src/strings/split/row.rs index 29838ce38..344a43b97 100644 --- a/crates/nu-command/src/strings/split/row.rs +++ b/crates/nu-command/src/strings/split/row.rs @@ -57,9 +57,11 @@ impl Command for SubCommand { example: "echo 'abc' | split row ''", result: Some(Value::List { vals: vec![ + Value::test_string(""), Value::test_string("a"), Value::test_string("b"), Value::test_string("c"), + Value::test_string(""), ], span: Span::test_data(), }), @@ -76,6 +78,20 @@ impl Command for SubCommand { span: Span::test_data(), }), }, + Example { + description: "Split a string by '-'", + example: "echo '-a-b-c-' | split row '-'", + result: Some(Value::List { + vals: vec![ + Value::test_string(""), + Value::test_string("a"), + Value::test_string("b"), + Value::test_string("c"), + Value::test_string(""), + ], + span: Span::test_data(), + }), + }, ] } } @@ -107,23 +123,11 @@ fn split_row_helper( match max_split { Some(max_split) => s .splitn(max_split, &separator.item) - .filter_map(|s| { - if s.trim() != "" { - Some(Value::string(s, v_span)) - } else { - None - } - }) + .map(|s| Value::string(s, v_span)) .collect(), None => s .split(&separator.item) - .filter_map(|s| { - if s.trim() != "" { - Some(Value::string(s, v_span)) - } else { - None - } - }) + .map(|s| Value::string(s, v_span)) .collect(), } } else {