csv
csv copied to clipboard
Fix: Allow \r in unquoted fields when row separator doesn't contain \r
Fixes #60
This has been bugging me for a while - the CSV parser was rejecting \r characters in unquoted fields even when the row separator was something completely different like \n or a custom separator.
For example, this would fail unnecessarily:
CSV.parse("field1,field\rwith\rcr,field3\n", row_sep: "\n")
The problem was in prepare_unquoted where we were hardcoding "\r\n" instead of checking what the actual row separator was.
What changed:
- Now we only exclude characters that are actually part of the row separator
- If your row separator is
\n, then\ris allowed in unquoted fields - If your row separator is
\r\n, then both\rand\nare still properly excluded - Quoted fields work exactly the same as before
Testing:
- Updated the tests that were expecting the old behavior
- Added comprehensive tests for different row separator scenarios
- All existing tests still pass
This makes the parser more flexible while keeping it safe for the cases where \r should actually be restricted.
@kou I've made all the changes asked.
@kou Thank you. I have:
- Removed the duplicate test
- Moved the unique tests to
test_general.rb - Fixed the misnamed test
- Deleted the separate test file
Thanks.