Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE-2431: Reduce floating point precision required of extended json implementations #369

Merged
merged 2 commits into from
Jul 8, 2020
Merged
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
14 changes: 11 additions & 3 deletions lib/double.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ class Double {
return { $numberDouble: `-${this.value.toFixed(1)}` };
}

return {
$numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
};
let $numberDouble;
if (Number.isInteger(this.value)) {
$numberDouble = this.value.toFixed(1);
if ($numberDouble.length >= 13) {
$numberDouble = this.value.toExponential(13).toUpperCase();
}
} else {
$numberDouble = this.value.toString();
}

return { $numberDouble };
}

/**
Expand Down
4 changes: 1 addition & 3 deletions test/node/bson_corpus_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ const skipBSON = {

const skipExtendedJSON = {
'Timestamp with high-order bit set on both seconds and increment':
'Current BSON implementation of timestamp/long cannot hold these values - 1 too large.',
'1.23456789012345677E+18': 'NODE-2519',
'-1.23456789012345677E+18': 'NODE-2519'
'Current BSON implementation of timestamp/long cannot hold these values - 1 too large.'
};

const corpus = require('./tools/bson_corpus_test_loader');
Expand Down
96 changes: 0 additions & 96 deletions test/node/specs/bson-corpus/README.md

This file was deleted.

10 changes: 8 additions & 2 deletions test/node/specs/bson-corpus/array.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
},
{
"description": "Single Element Array with index set incorrectly",
"description": "Single Element Array with index set incorrectly to empty string",
"degenerate_bson": "130000000461000B00000010000A0000000000",
"canonical_bson": "140000000461000C0000001030000A0000000000",
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
},
{
"description": "Single Element Array with index set incorrectly",
"description": "Single Element Array with index set incorrectly to ab",
"degenerate_bson": "150000000461000D000000106162000A0000000000",
"canonical_bson": "140000000461000C0000001030000A0000000000",
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
},
{
"description": "Multi Element Array with duplicate indexes",
"degenerate_bson": "1b000000046100130000001030000a000000103000140000000000",
"canonical_bson": "1b000000046100130000001030000a000000103100140000000000",
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}, {\"$numberInt\": \"20\"}]}"
}
],
"decodeErrors": [
Expand Down
Empty file modified test/node/specs/bson-corpus/binary.json
100755 → 100644
Empty file.
Empty file modified test/node/specs/bson-corpus/boolean.json
100755 → 100644
Empty file.
Empty file modified test/node/specs/bson-corpus/code.json
100755 → 100644
Empty file.
Empty file modified test/node/specs/bson-corpus/code_w_scope.json
100755 → 100644
Empty file.
6 changes: 6 additions & 0 deletions test/node/specs/bson-corpus/datetime.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"description" : "Y10K",
"canonical_bson" : "1000000009610000DC1FD277E6000000",
"canonical_extjson" : "{\"a\":{\"$date\":{\"$numberLong\":\"253402300800000\"}}}"
},
{
"description": "leading zero ms",
"canonical_bson": "10000000096100D1D6D6CC3B01000000",
"relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.001Z\"}}",
"canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330001\"}}}"
}
],
"decodeErrors": [
Expand Down
Empty file modified test/node/specs/bson-corpus/dbpointer.json
100755 → 100644
Empty file.
Empty file modified test/node/specs/bson-corpus/dbref.json
100755 → 100644
Empty file.
Empty file modified test/node/specs/bson-corpus/decimal128-1.json
100755 → 100644
Empty file.
Empty file modified test/node/specs/bson-corpus/decimal128-2.json
100755 → 100644
Empty file.
Empty file modified test/node/specs/bson-corpus/decimal128-3.json
100755 → 100644
Empty file.
Loading