Skip to content

fix(csv-parse): consume full trim characters after closing quotes - #541

Open
pauloflp wants to merge 1 commit into
adaltas:masterfrom
pauloflp:fix/trim-multibyte-after-quotes-20261025
Open

pauloflp wants to merge 1 commit into
adaltas:masterfrom
pauloflp:fix/trim-multibyte-after-quotes-20261025

Conversation

@pauloflp

Copy link
Copy Markdown

With rtrim: true or trim: true, whitespace after a closing quote is recognized but only its first byte is skipped. The remaining bytes then trigger CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE.

For example, parse(Buffer.from('"a"\u3000,"b"'), { trim: true }) currently throws instead of returning [['a', 'b']]. UTF-16LE also fails with ordinary spaces because they occupy two bytes.

Advance past the complete matched trim character when discarding trailing whitespace, as the leading-whitespace path already does. Add regressions for UTF-8 and UTF-16LE, both options, empty quoted fields, field/record boundaries and EOF, preservation of whitespace inside quotes, one-byte stream writes, and rejection of a non-whitespace character after the padding.

Validation on Node.js v24.22.1:

  • The new tests produce 8 failures before the source fix.
  • npm run test --workspace=csv-parse: 641 passing, 2 pending; TypeScript check passes.
  • ESLint on both changed files passes.
  • npm run build --workspace=csv-parse passes.

Related to the whitespace support introduced in #483. This addresses consuming already-recognized trim characters after quotes; it does not change the BOM state refresh in #537. The fixtures specify their record delimiter to keep this separate from #539.

AI-assisted implementation and local verification.

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.

1 participant