forked from extern/nushell
Changes the parsing to use the full value of the final column.
Previously it would split the last column on the first separator value found between the start of the column and the end of the row. Changing this to using everything from the start of the column to the end of the string makes it behave more similarly to the other columns, making it less surprising.
This commit is contained in:
parent
9b1ff9b566
commit
305ca11eb5
@ -75,7 +75,7 @@ fn string_to_table(
|
|||||||
.filter_map(|(i, (start, col))| {
|
.filter_map(|(i, (start, col))| {
|
||||||
(match columns.get(i + 1) {
|
(match columns.get(i + 1) {
|
||||||
Some((end, _)) => l.get(*start..*end),
|
Some((end, _)) => l.get(*start..*end),
|
||||||
None => l.get(*start..)?.split(&separator).next(),
|
None => l.get(*start..),
|
||||||
})
|
})
|
||||||
.and_then(|s| Some((col.clone(), String::from(s.trim()))))
|
.and_then(|s| Some((col.clone(), String::from(s.trim()))))
|
||||||
})
|
})
|
||||||
@ -298,16 +298,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_drops_trailing_values() {
|
fn it_uses_the_full_final_column() {
|
||||||
let input = r#"
|
let input = r#"
|
||||||
colA col B
|
colA col B
|
||||||
val1 val2 trailing value that should be ignored
|
val1 val2 trailing value that should be included
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let result = string_to_table(input, false, 2).unwrap();
|
let result = string_to_table(input, false, 2).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result,
|
result,
|
||||||
vec![vec![owned("colA", "val1"), owned("col B", "val2"),],]
|
vec![vec![owned("colA", "val1"), owned("col B", "val2 trailing value that should be included"),],]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user