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

ux.Table: Incorrect parsing of double quotes when exporting to CSV #944

Closed
julesbonnard opened this issue Feb 8, 2024 · 3 comments
Closed

Comments

@julesbonnard
Copy link
Contributor

Describe the bug
The CSV output of ux.Table only escapes the first double quote of a string value, resulting in a bad CSV format when exporting string values with multiple double quotes followed by a comma.

To Reproduce
Try exporting with --csv flag a table containing the following string: "That film", a great movie.
You get this wrong result: """That film", a great movie"

Expected behavior
According to CSV spec If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote., the correct export should be """That film"", a great movie"

Additional context
Problem seems to come from this line :

return values.map((e) => (lineToBeEscaped ? `"${e.replace('"', '""')}"` : e))
, where replaceAll should be used instead of replace.

Also, it would be great to only escape values containing characters like double quotes, commas and line breaks, and not the entire line

Thanks for your help

@mdonnalley
Copy link
Contributor

@julesbonnard Sounds like you've around got your head wrapped around a solution - any chance you'd be willing to submit a PR?

@julesbonnard
Copy link
Contributor Author

julesbonnard commented Feb 23, 2024 via email

julesbonnard added a commit to julesbonnard/core that referenced this issue Feb 28, 2024
modify replace with replaceAll as mentioned in this issue : oclif#944 (comment)
mdonnalley pushed a commit that referenced this issue Mar 1, 2024
…977)

* Fix: correctly escapes double quotes when converting ux.table to csv

modify replace with replaceAll as mentioned in this issue : #944 (comment)

* test: complete ux.table test to check if double quotes escaping is correct
mdonnalley added a commit that referenced this issue Mar 1, 2024
…977) (#980)

* Fix: correctly escapes double quotes when converting ux.table to csv

modify replace with replaceAll as mentioned in this issue : #944 (comment)

* test: complete ux.table test to check if double quotes escaping is correct

Co-authored-by: Jules Bonnard <[email protected]>
@mdonnalley
Copy link
Contributor

Closed by #980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants