BurntSushi / BurntSushi/rust-csv
Space after delimiter messes with quoting
- Dominant language
- Rust
- Stars
- 2k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
#### What version of the `csv` crate are you using?
1.2.2
#### Briefly describe the question, bug or feature request.
When parsing a CSV file which has a space following each comma, whether or not I enable trimming, the presence of the space seems to override the default quoting behaviour and cause " to be included in the output rather than function as a quote.
Quoting is set to true by default, and explicitly setting it to true has no effect.
Changing the quote character and leaving in the space after the comma has the same effect.
#### Include a complete program demonstrating a problem.
```
#[test]
fn test_parse_csv() {
let data = "\
我的頭髮太厚了,我要打薄, \"My hair is too thick, I need to thin it out\"
我朋友是個街友*基金會*的員工, My friend works at a homelessness charity
基金會
";
let mut input_csv_reader = csv::ReaderBuilder::new()
.flexible(true)
.has_headers(false)
// .trim(csv::Trim::All)
.from_reader(data.as_bytes());
let first_row = input_csv_reader.records().next().unwrap().unwrap();
println!("First Row: {:?}", first_row);
assert_eq!(first_row.len(), 2);
}
```
#### What is the observed behavior of the code above?
```
running 1 test
First Row: StringRecord(["我的頭髮太厚了,我要打薄", " \"My hair is too thick", " I need to thin it out\""])
thread 'test_parse_csv' panicked at 'assertion failed: `(left == right)`
left: `3`,
right: `2`', src/main.rs:731:5
```
#### What is the expected or desired behavior of the code above?
The CSV should be parsed correctly, with the quoted sentence all appearing as one value.
Or at least there should be a setting to enable handling this scenario.
Currently the only setting that sounds related is `trim`, but it doesn't have any impact.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.