Skip to content

fix: defer newline detection for a CR at the end of a chunk - #253

Open
codeofwxz wants to merge 1 commit into
mafintosh:masterfrom
codeofwxz:fix/defer-cr-newline-detection
Open

codeofwxz wants to merge 1 commit into
mafintosh:masterfrom
codeofwxz:fix/defer-cr-newline-detection

Conversation

@codeofwxz

Copy link
Copy Markdown

This PR contains:

  • bugfix
  • feature
  • refactor
  • tests
  • documentation
  • metadata

Breaking Changes?

  • yes
  • no

If yes, please describe the breakage.

Please Describe Your Changes

When the first CRLF is split across chunks, newline detection treats the trailing CR as a standalone separator before the LF arrives. The example in #234 consequently produces an extra record and leading LF characters in values.

Defer this decision until the next chunk, revisiting the pending CR without counting it twice towards maxRowBytes. Preserve existing EOF handling, custom newline behavior, and quoted content.

Add nine tests covering the reported split, representative boundaries and byte-by-byte input, empty chunks, standalone CR, EOF, custom newlines, quoted CRLF, skipped lines/comments, byte offsets, and row-size limits. Also fix the pre-existing missing space in the sanitizeHeader declaration so ESLint passes.

Validation on Windows with Node 24.19.0: all 50 AVA tests passed, plus tsd and ESLint. The existing shell-based CLI test used the installed PowerShell as ComSpec; no tests were skipped or changed to accommodate Windows. Fixtures were checked using their original repository bytes.

Fixes #234.

Hosted CI and other Node versions have not been verified; the results above are local validation.

Copilot AI lite review requested due to automatic review settings September 12, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reported bug is addressed with comprehensive regression coverage and no unresolved blocking issues.

Pull request overview

Fixes CRLF detection when \r and \n arrive in separate chunks.

Changes:

  • Defers processing of trailing CR bytes.
  • Adds comprehensive chunk-boundary and edge-case tests.
  • Fixes sanitizeHeader formatting.
File summaries
File Description
test/newline-chunks.test.js Adds regression and boundary tests.
index.js Implements deferred CR handling and formatting fix.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

\r and \n arriving in separate chunks breaks line separator detection

2 participants