Skip to content

Commit 30f5a8f

Browse files
committed
fix: improve EJSON generation for previously skipped edge cases
These cases were explicitly disabled in the BSON corpus test runner but are now supported.
1 parent 35b151c commit 30f5a8f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Diff for: lib/double.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
/**
34
* A class representation of the BSON Double type.
45
*/
@@ -41,16 +42,22 @@ class Double {
4142
if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
4243
return this.value;
4344
}
44-
return { $numberDouble: this.value.toString() };
45+
46+
if (Object.is(Math.sign(this.value), -0)) {
47+
return { $numberDouble: `-${this.value.toFixed(1)}` };
48+
}
49+
50+
return {
51+
$numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
52+
};
4553
}
4654

4755
/**
4856
* @ignore
4957
*/
5058
static fromExtendedJSON(doc, options) {
51-
return options && options.relaxed
52-
? parseFloat(doc.$numberDouble)
53-
: new Double(parseFloat(doc.$numberDouble));
59+
const doubleValue = parseFloat(doc.$numberDouble);
60+
return options && options.relaxed ? doubleValue : new Double(doubleValue);
5461
}
5562
}
5663

0 commit comments

Comments
 (0)