Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alecmev opened this issue Sep 25, 2023 · 0 comments
Open

Comments

@alecmev
Copy link

alecmev commented Sep 25, 2023

  • 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?

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.

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

No branches or pull requests

1 participant