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

Options for Enclosure, Delimiter & Escape #21

Closed
slpixe opened this issue Mar 30, 2019 · 5 comments
Closed

Options for Enclosure, Delimiter & Escape #21

slpixe opened this issue Mar 30, 2019 · 5 comments

Comments

@slpixe
Copy link

slpixe commented Mar 30, 2019

Hi, Really nice library, and its cool that it supports arrays and objects, and mapping of headers 👍

Seen a few similar previous issues regarding the Delimiter, but I was curious about having enclosures e.g. "value"

I can see you already have a

needsQuote()

for having enclosures for fields that would require it, but it be pretty nice to have the option for all fields to have this.

Although CSV isn't a defined spec, it is mentioned on RFC 4180,

Each field may or may not be enclosed in double quotes

and a other languages library(ies) have supported these options:
[1] https://github.com/thephpleague/csv

My thoughts would be having the enclosure be optional, and if undefined and a field needs quoting it gets quoted as currently works.
But that if a enclosure of " is passed through it could wrap all fields.

More information here:
https://csv.thephpleague.com/9.0/connections/controls/

@ryu1kn
Copy link
Owner

ryu1kn commented Mar 31, 2019

Hello @slpixe , thanks for the suggestion.

So, you want an option to always double quote all field values. Do you mind sharing why you want that option?

@vergissberlin
Copy link

In my case, I want to create test data that is very close to the original one.
The original uses quotes for every field.

André

@phillipplum
Copy link

Hey @ryu1kn, thanks for the nice library.
I also need this option. The external software for which we write the CSV does not read the CSV correctly without quotation marks.

@ryu1kn
Copy link
Owner

ryu1kn commented Jun 25, 2019

Already 3 people raising this. (Sorry I somehow missed your comment, @vergissberlin ...) Seems like some programmes are picky on this...

And as @slpixe pointed, from RFC 4180 perspective, quoting all fields is possible too.

Each field may or may not be enclosed in double quotes

I was kind of reluctant to introduce this as I think it's parser's responsibility to deal with all valid CSVs (plus I didn't want to complicate csv-writer even it would be minor). But given the reality, I think it's reasonable to allow csv-writer to produce fields always with quotes.

@ryu1kn
Copy link
Owner

ryu1kn commented Jul 13, 2019

Introduced alwaysQuote flag. Released as v1.5.0.

@ryu1kn ryu1kn closed this as completed Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants