Skip to content

fix: throw on invalid Date serialization instead of producing NaN string (#3318) - #3722

Closed
marceli1404 wants to merge 1 commit into
brianc:masterfrom
marceli1404:fix/invalid-date-serialization
Closed

fix: throw on invalid Date serialization instead of producing NaN string (#3318)#3722
marceli1404 wants to merge 1 commit into
brianc:masterfrom
marceli1404:fix/invalid-date-serialization

Conversation

@marceli1404

Copy link
Copy Markdown

Description

new Date(undefined) (an invalid Date) was serialized as "0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN" which is meaningless and harmful for Postgres queries.

Changes

  • Added isNaN(val.getTime()) check in prepareValue() in packages/pg/lib/utils.js when handling Date objects
  • Throws a clear Error('Invalid Date value provided to query parameter') when an invalid date is detected
  • Added unit tests for invalid dates: new Date(undefined), new Date(NaN), new Date('not a date')

Valid dates continue to work as before.

Closes #3318

new Date(undefined) (an invalid Date) was serialized as
'0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN' which is meaningless
and harmful for Postgres queries. Now throws a clear error.

Closes brianc#3318
@charmander charmander closed this Jul 29, 2026
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.

Do not serialize new Date(undefined) as "0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN"

2 participants