Skip to content

fix(stringify): reject invalid values in cast option objects - #511

Merged
wdavidw merged 3 commits into
adaltas:masterfrom
kirisue:fix/stringify-cast-option-value
Sep 30, 2026
Merged

wdavidw merged 3 commits into
adaltas:masterfrom
kirisue:fix/stringify-cast-option-value

Conversation

@kirisue

@kirisue kirisue commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

csv-stringify silently writes an empty field when a custom cast returns an options object whose value is 0 or false:

stringify([['input']], { cast: { string: () => ({ value: 0 }) } })
// before: '\n'; after: throws Invalid Casting Value

The existing type guard allows only strings, null and undefined, but an unrelated if (err) prevents it from reporting the invalid value. Remove that condition so invalid values are rejected before formatting. Valid string, null and undefined values retain their existing behavior.

Add regression cases for 0 and false in both the callback and synchronous public APIs, plus a control covering the allowed value types. Unsupported truthy values are also rejected by this earlier guard and now receive its Invalid Casting Value message rather than the later Formatter message.

Validation on Node.js 24.19.0:

  • The four invalid-value regressions fail before the source change and pass afterward.
  • Focused cast suite: 7 passed.
  • npm test --workspace csv-stringify: TypeScript check passed; 232 tests passed, 1 pre-existing pending test.
  • ESLint and Prettier on both changed files: passed.
  • No generated distribution, dependency or lockfile changes.

Prepared with OpenAI Codex; the listed tests were executed locally.

@wdavidw

wdavidw commented Sep 28, 2026

Copy link
Copy Markdown
Member

Hi @kirisue, could you provide me with the permission to push into your fork. I wish to update the tests.

@kirisue

kirisue commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Hi @wdavidw, I've enabled “Allow edits by maintainers” for this PR. You should now be able to push the test updates directly to the branch. Thanks for taking a look!

@wdavidw
wdavidw force-pushed the fix/stringify-cast-option-value branch from af28eb1 to 44f53d8 Compare September 30, 2026 13:24
@wdavidw
wdavidw merged commit a47824d into adaltas:master Sep 30, 2026
@wdavidw

wdavidw commented Sep 30, 2026

Copy link
Copy Markdown
Member

Thank you @kirisue for your involvement.

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.

2 participants