Repository navigation
fix: escape double quotes in the --output CSV file - #477
Open
LemonCondor wants to merge 1 commit into
Open
LemonCondor wants to merge 1 commit into
LemonCondor wants to merge 1 commit into
Conversation
A double quote in a query was written as \" and quotes in the other text fields were not escaped at all, so CSV readers split the row on the wrong delimiters. Double the quotes in every field, as in RFC 4180.
Collaborator
|
Hi thanks for contributing ! We have a MR on the same general area here, do you have an opinion on this? |
Author
|
I agree with you: pausing should freeze the display, not the recording. With This PR only changes how values are quoted in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The CSV file written by
--outputcan be read back with shifted columns when a value contains a double quote:"was written as\", which is not how CSV escapes quotes;For example, with the query
SELECT * FROM "Users";, Python'scsv.reader(f, delimiter=";")returns 17 fields for a 16-column header, and the query comes back asSELECT * FROM \Users\".This change doubles the quotes in every field (RFC 4180). The output is unchanged for values without double quotes. Anything that relied on the
\"form would now see""instead.tests/test_csv_write.pyfails onmasterfor the four text fields and passes with the change. I also ran the doctests ofpgactivity/utils.py,tests/test_reconnect.py, black, flake8, isort, codespell and mypy on the touched module. I did not run the tests that need a PostgreSQL server.