-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: BSON
Our serializeInto function currently checks if any passed in values to be serialized
have a toBSON method defined on them in all cases excepting the values of
Map entries.
The omission of this check seems to be in error and may produce unexpected results
for users who expect consistent behaviour across supplied values.
User Impact
Unsure as we do not know how many users rely on this feature being consistent for their workflows.
Acceptance Criteria
- serializeInto checks for toBSON method on values of Map entries
- Write tests to ensure that we check for toBSON method on values passed to serializedInto on all paths
Steps to reproduce
The following code snippet demonstrates the difference the serialization and subsequent
deserialization of an Object and a Map with the same keys and values.
const BSON = require('bson'); // Add toBSON method to numbers Number.prototype.toBSON = function() { return `Number: ${this.valueOf()}` } const object = {"a": 1, "b":2}; const map = new Map(); map.set("a", 1); map.set("b", 2); console.log(BSON.deserialize(BSON.serialize(map))); // { a: 1, b: 2 } console.log(BSON.deserialize(BSON.serialize(object))); // { a: 'Number: 1', b: 'Number: 2' }
- related to
-
NODE-4870 Support BigInt serialization in js-bson
- Closed