-
Type: Bug
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
Use Case
BSON and EJSON currently have questionable behavior when serializing dates:
EJSON
> ejson.stringify({ d : new Date(2 ** 60 ) }) '{"d":{"$date":{"$numberLong":"NaN"}}}' > ejson.parse(ejson.stringify({ d : new Date(2 ** 60 ) })) Uncaught BSONError: $numberLong string "NaN" is in an invalid format
BSON
> bson.serialize({ a: new Date(2 ** 60 ) }) <Buffer 10 00 00 00 09 61 00 00 00 00 00 00 00 00 00 00> > bson.deserialize(bson.serialize({ a: new Date(2 ** 60 ) })) { a: 1970-01-01T00:00:00.000Z }
Both of these behaviors are problematic because they allow users to serialize data but then prevent the user from correctly deserializing it. Anything we serialize (with bson or EJSON) with errors should be deserializable with no loss of precision or modifications of data.
*BSON and EJSON should throw an error when attempting to serialize an invalid date.
This behavior has existed since bson@1.x.
User Impact
- Unsure. It seems unlikely that users are round-tripping invalid dates through BSON, but it's possible.
Dependencies
- n/a
Unknowns
- Does this need to be done in a major release?
Acceptance Criteria
Implementation Requirements
- Throw an error when serializing a date if `Date.getTime()` returns `NaN`. This applies to both BSON and EJSON.
Testing Requirements
Documentation Requirements
n/a
Follow Up Requirements
n/a
- is depended on by
-
MONGOSH-1735 Cannot pass invalid date values through node-runtime-worker-threads
- Waiting (Blocked)