Skip to content
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

encoding/csv: documentation of UseCRLF is incomplete #47774

Open
rs-blade opened this issue Aug 18, 2021 · 3 comments
Open

encoding/csv: documentation of UseCRLF is incomplete #47774

rs-blade opened this issue Aug 18, 2021 · 3 comments
Labels
Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rs-blade
Copy link

According to the documentation of the UseCRLF flag here:

// If UseCRLF is true, the Writer ends each output line with \r\n instead of \n.

it only influences the line terminator. When looking at the code one can see that setting that flag to true also impacts the output of the cell content: \r is removed and \n replaced by \r\n.
This behavior should also be reflected in the documentation!

@seankhliao
Copy link
Member

csv doesn't escape newlines in cell contents, so if there's a newline in a cell it is also the end of an output line.

"hello", "foo\nbar", "world"
as csv would be

hello,"foo
bar",world

@rs-blade
Copy link
Author

You're right. What I meant when writing \r and \n was the characters 13 and 10.
So to be clear: If UseCRLF is true a string of chars 0x41 0x0d 0x42 will become 0x22 0x41 0x42 0x22. So a quoted string where the 0x0d is removed (see here:

case '"':
)
On the other hand 0x41 0x0a 0x42 becomes 0x22 0x41 0x0d 0x0a 0x42 0x22 (see here:
_, err = w.w.WriteString("\r\n")
)

I think this is important to know, so the documentation should tell you about that behavior.

@mknyszek mknyszek changed the title Documentation of UseCRLF in encoding/csv/writer is incomplete encoding/csv: documentation of UseCRLF is incomplete Aug 18, 2021
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 18, 2021
@mknyszek mknyszek added this to the Backlog milestone Aug 18, 2021
@seankhliao
Copy link
Member

I understood that part, I'm saying that because it's not escaped in csv, an output line != single record and it changes all output line endings, not just end of record endings.
But feel free to send a PR/CL with what you think would make it clearer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants