You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Allow \r in unquoted fields when row separator doesn't contain \r (#346)
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:
```ruby
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 `\r` is allowed in unquoted fields
- If your row separator is `\r\n`, then both `\r` and `\n` are 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.
---------
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
0 commit comments