instride-ch/pimcore-data-definitions

CSV escape character should be at least empty or configurable in export definitions

Opened this issue · 0 comments

slri commented
Q A
Bug report? yes
Feature request? yes
BC Break report? no
RFC? no
Branch? master

As it is right now CsvProvider doesn't even allow you to configure the escape character to be anything other than the default \. This poses a problem when exporting JSON in CSV because it has the tendency to break the necessary CSV quote escapes due to JSON needing it's own escapes for quotes inside strings.

Example JSON:

{"prop":"value with \"escaped double quotes\""}

Expected result:

"{""prop"":""value with \""escaped double quotes\""""}"

Actual result:

"{""prop"":""value with \"escaped double quotes\"""}"

The actual result breaks CSV columns, making the CSV data pretty much garbage (notice the JSON escaped quotes missing the CSV escaping in the actual result).
Due to the way that fputcsv works, escaping the escape character (eg. \\) doesn't change anything. Allowing for escape to be an empty string removes this limitation altogether and some specific usecases could benefit from escape character for CSV being configurable in the profile itself.

Bugfix:
Use empty string as the escape character passed to Writer.

Feature:
Allow escape character to be configured per profile, defaulting to empty string if none is present.