mafintosh / mafintosh/csv-parser
`\r` and `\n` arriving in separate chunks breaks line separator detection
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 143
- PR merge metrics
- No merged PRs in 30d
Description
* Operating System: Any
* Node Version: Any
* NPM Version: Any
* csv-parser Version: 3.0.0
### Expected Behavior
The assert in the repro passes.
### Actual Behavior
The assert in the repro fails.
### How Do We Reproduce?
```ts
import { deepStrictEqual } from 'node:assert';
import { Readable } from 'node:stream';
import csvParserFactory from 'csv-parser';
deepStrictEqual(
await Readable.from(["foo\r", "\nbar\r\n", "baz\r\n"])
.pipe(csvParserFactory())
.toArray(),
await Readable.from(["foo\r\n", "bar\r\n", "baz\r\n"])
.pipe(csvParserFactory())
.toArray(),
);
```
### Cause
This happens because `csv-parser` is fine with `nextChr` being `null` when `this.state.first` is `true`. Instead it should wait until there's at least one more byte or the input stream is closed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Readable-stream repro against csv-parser and inspect the parser's handling of nextChr and state.first when chunks split a line separator. Done means the chunked input produces the same rows as input containing complete \r\n sequences, with the existing assertion passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100