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:
```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.
合并状态:已合并 合并于 2025-07-04 关闭于 2025-07-04 2 条评论