Skip to content

fix(csv-stringify): quote empty strings returned by casts - #521

Open
sunlishuo25 wants to merge 1 commit into
adaltas:masterfrom
sunlishuo25:fix/csv-stringify-cast-empty-quotes
Open

sunlishuo25 wants to merge 1 commit into
adaltas:masterfrom
sunlishuo25:fix/csv-stringify-cast-empty-quotes

Conversation

@sunlishuo25

Copy link
Copy Markdown

When a cast changes a field to an empty string, quoted_match: /^$/ and quoted_string: true omit the quotes:

stringify([[' ']], {
  quoted_match: /^$/,
  cast: { string: value => value.trim() }
});
// before: '\n'; after: '""\n'

Select the empty-string branch using the cast value, while keeping quoted_string limited to original string fields. Tests cover callback and sync APIs, field-level options, null/undefined, non-string fields, and quoted_empty: false.

The default boolean cast returns '' for false, so false now also matches quoted_match: /^$/. Null and undefined stay unquoted with that option.

Validation on Node 24.16.0:

  • Four regressions fail before the fix; all 19 focused tests pass afterward.
  • npm test --workspace csv-stringify -- --no-parallel: TypeScript passed, 237 tests passed, 1 existing pending test.
  • Stream pipeline through csv-parse, ESLint and Prettier passed.
  • Isolated package build passed; packed CommonJS and actual-browser ESM/IIFE/UMD sync and callback entries passed.
  • Independent distribution checks passed 36 CJS and 72 browser assertions, plus 6 environment checks.

Node 20/22 and the wider browser matrix were not run locally. Generated files are omitted, following recent source-fix PRs and the package's release build scripts.

Developed with GPT assistance.

@sunlishuo25
sunlishuo25 marked this pull request as ready for review October 4, 2026 16:22
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