-
-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quotes included despite using QuoteStyle::Never #276
Comments
My initial impression here is that this is a bug, since the After a brief skim of the code, I couldn't immediately identify where the quotes are being inserted. But I think I'd accept a patch that fixes this. With that said, there is a possible work-around here: simply do not write empty records. Unless you're feeding the data to some other parser---as I mentioned above---the parser in this crate will just ignore empty lines anyway. So it will be as if the record was never written at all. |
I need the empty line because the output will be parsed by another tool which is not necessarily a CSV parser, which doesn't mind empty fields. This already works when there is more than one field in the record: writer.write_record(["a", "b"]).unwrap();
writer.write_record(["c", ""]).unwrap();
writer.write_record(["", "d"]).unwrap(); This produces the following, as expected:
But if there is only one record, empty field gets quoted. I don't have access to writer's output, so I cannot inject the newline myself. The intended use is to pipe the output into tools like |
Looking at the code, this line could be the origin of the quotes: pub fn finish(&mut self, mut output: &mut [u8]) -> (WriteResult, usize) {
let mut nout = 0;
if self.state.record_bytes == 0 && self.state.in_field {
assert!(!self.state.quoting);
let (res, o) = self.write(&[self.quote, self.quote], output); Would you accept a PR that modifies this to quote only if quoting style is something other than |
I think so yes, but I'll need to think on it. In particular, the line right above rust-csv/csv-core/src/writer.rs Line 234 in 41c71ed
suggests that I might have added this explicit quoting because of some other reason that I can no longer remember. And I wish I had left a comment. |
The docs for
QuoteStyle::Never
say:Based on that, I would expect the following program to output a line with
foo
followed by an empty line, followed by a line withbar,baz
:Expected output:
But actual output is:
Is there a way to prevent the writer from generating quotes?
I am using csv 1.1.6.
The text was updated successfully, but these errors were encountered: