Skip to content

Commit 2a5ed28

Browse files
committed
test: non-string _bsontype is allowed
1 parent d691473 commit 2a5ed28

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/node/parser/serializer.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ describe('serialize()', () => {
4949
);
5050
});
5151

52+
it('does permit objects with a _bsontype prop that is not a string', () => {
53+
const expected = bufferFromHexArray([
54+
'10', // int32
55+
Buffer.from('_bsontype\x00', 'utf8').toString('hex'),
56+
'02000000'
57+
]);
58+
const result = BSON.serialize({ _bsontype: 2 });
59+
expect(result).to.deep.equal(expected);
60+
61+
expect(() => BSON.serialize({ _bsontype: true })).to.not.throw();
62+
expect(() => BSON.serialize({ _bsontype: /a/ })).to.not.throw();
63+
expect(() => BSON.serialize({ _bsontype: new Date() })).to.not.throw();
64+
});
65+
5266
it('does not permit non-objects as the root input', () => {
5367
// @ts-expect-error: Testing invalid input
5468
expect(() => BSON.serialize(true)).to.throw(/does not support non-object/);

0 commit comments

Comments
 (0)