Repository navigation
Conversation
A UTF-8, Shift_JIS, or EUC-JP field with one bad byte and a newline, comma, or quote was written raw. The same field without the bad byte was quoted, so a consumer that accepts the byte saw an extra row.
The quote check skipped the regexp when valid_encoding? was false, because match? raises. The field was then written raw, so a newline or comma inside it became another row. The check now looks for those bytes with String#include?. Fixes ruby#395
This branch has not been deployed
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.
Fixes #395.
The writer quoted a field when it contained a newline, a comma, or a quote. That check used a regexp, and
Regexp#match?raises on an invalid byte, so the code skipped the check whenevervalid_encoding?was false and wrote the field raw.A UTF-8 field
"x\xFF\nadmin,true"was emitted as two lines. The same text without the bad byte, and the same bytes tagged as ASCII-8BIT, were quoted. Shift_JIS and EUC-JP did the same. A byte-oriented reader then saw a row the writer never produced:An invalid field that contains none of those characters is still written unquoted. A field that also contains a quote still doubles it. The full suite passes with and without
CSV_PARSER_SCANNER_TEST=yes(537 tests, 4092 assertions).