Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/pg/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ const prepareValue = function (val, seen) {
return buf.slice(val.byteOffset, val.byteOffset + val.byteLength) // Node.js v4 does not support those Buffer.from params
}
if (isDate(val)) {
if (isNaN(val.getTime())) {
throw new Error('date is invalid')
}
if (defaults.parseInputDatesAsUTC) {
return dateToStringUTC(val)
} else {
Expand Down
16 changes: 16 additions & 0 deletions packages/pg/test/unit/utils-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@
assert.strictEqual(out, null)
})

test('prepareValues: invalid date throws an error', function () {
const invalidDate = new Date(undefined)
assert.throws(

Check failure on line 99 in packages/pg/test/unit/utils-tests.js

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····()·=>·utils.prepareValue(invalidDate),⏎····/date·is·invalid/⏎··` with `()·=>·utils.prepareValue(invalidDate),·/date·is·invalid/`
() => utils.prepareValue(invalidDate),
/date is invalid/
)
})

test('prepareValues: invalid date (NaN) does not produce NaN string', function () {
const invalidDate = new Date('not a date')
assert.throws(

Check failure on line 107 in packages/pg/test/unit/utils-tests.js

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····()·=>·utils.prepareValue(invalidDate),⏎····/date·is·invalid/⏎··` with `()·=>·utils.prepareValue(invalidDate),·/date·is·invalid/`
() => utils.prepareValue(invalidDate),
/date is invalid/
)
})

test('prepareValue: null prepared properly', function () {
const out = utils.prepareValue(null)
assert.strictEqual(out, null)
Expand Down
Loading