Repository navigation
Conversation
Member
|
Is this not somehow related to #545 ? |
Author
Yes, they are related! Both address UTF-16LE byte alignment, but at different stages of parsing. #545 fixes delimiter matching, preventing unaligned bytes from being interpreted as field or record separators. #542 fixes the separate physical line counter, which can incorrectly count CR/LF bytes within ordinary UTF-16LE characters. This affects info.lines, from_line, to_line, and error locations. The fixes are complementary, and the tests target different behaviors. Happy to coordinate or adjust the implementation if needed. Thanks for pointing this out! |
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.
UTF-16LE characters can contain
0x0aor0x0dwithout containing a newline. The parser currently counts those individual bytes as line breaks, soinfo.linesand error locations become incorrect,from_linestarts too early, andto_linecan discard valid records.Minimal reproduction:
Count CR/LF only when they form a complete UTF-16LE code unit at an aligned byte offset. Determine the encoding after BOM detection, and use the cumulative byte offset so alignment remains correct across arbitrary stream chunks. Other encodings retain their existing line-counting path.
Add nine regression tests covering CR/LF bytes in either byte of a character, unaligned byte pairs, encoding aliases, genuine LF/CR/CRLF record endings, quoted newlines, comments, error locations,
from_line,to_line, and one-byte writes with explicit encoding or BOM detection.Validation on Node.js v24.22.1:
npm run test --workspace=csv-parse: 638 passing, 2 pending; TypeScript passes.git diff --checkpass.npm run build --workspace=csv-parsepasses.This PR targets line counting. Record/field delimiter matching at unaligned offsets is a separate existing issue; the alignment-specific line-count regression uses
|to isolate that behavior. AI-assisted implementation and local verification.