Skip to content

Commit

Permalink
fix(NODE-6608): calculateObjectSize returns the wrong value for bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Dec 16, 2024
1 parent 26549d9 commit 3f22a32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/parser/calculate_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ function calculateElement(
1
);
}
return 0;
case 'bigint':
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
}

return 0;
Expand Down
6 changes: 6 additions & 0 deletions test/node/parser/calculate_size.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 3f22a32

Please sign in to comment.