Skip to content

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

Description

@alecmev
  • 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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions