From 3f22a322151ed9f89586af94e52a6847654a3681 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 11:03:10 -0500 Subject: [PATCH] fix(NODE-6608): calculateObjectSize returns the wrong value for bigint --- src/parser/calculate_size.ts | 3 +++ test/node/parser/calculate_size.test.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/parser/calculate_size.ts b/src/parser/calculate_size.ts index 923beeb0b..da62ae6cd 100644 --- a/src/parser/calculate_size.ts +++ b/src/parser/calculate_size.ts @@ -205,6 +205,9 @@ function calculateElement( 1 ); } + return 0; + case 'bigint': + return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1); } return 0; diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index 3ebccd160..e421c28f2 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -24,4 +24,10 @@ describe('calculateSize()', () => { }) ).to.throw(BSONVersionError, /Unsupported BSON version/i); }); + + it('returns the correct size for a bigint value', function () { + const doc = { a: BigInt(1) }; + expect(BSON.calculateObjectSize(doc)).to.equal(16); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); });