diff --git a/crates/nu-command/src/formats/from/ssv.rs b/crates/nu-command/src/formats/from/ssv.rs index 2fdb40ee80..7df3b809da 100644 --- a/crates/nu-command/src/formats/from/ssv.rs +++ b/crates/nu-command/src/formats/from/ssv.rs @@ -239,7 +239,9 @@ fn string_to_table( aligned_columns: bool, split_at: usize, ) -> Vec> { - let mut lines = s.lines().filter(|l| !l.trim().is_empty()); + let mut lines = s + .lines() + .filter(|l| !l.trim().is_empty() && !l.trim().starts_with('#')); let separator = " ".repeat(std::cmp::max(split_at, 1)); let (ls, header_options) = if noheaders { @@ -314,6 +316,24 @@ mod tests { (String::from(x), String::from(y)) } + #[test] + fn it_filters_comment_lines() { + let input = r#" + a b + 1 2 + 3 4 + #comment line + "#; + let result = string_to_table(input, false, true, 1); + assert_eq!( + result, + vec![ + vec![owned("a", "1"), owned("b", "2")], + vec![owned("a", "3"), owned("b", "4")] + ] + ); + } + #[test] fn it_trims_empty_and_whitespace_only_lines() { let input = r#"