Skip to content

Commit aba3a18

Browse files
author
Sophie Saskin
authored
fix(serializer): map insert expects only string keys
Checks that the key is a string before checking that the key is a valid string to prevent type error. Fixes NODE-1572
1 parent cbb4724 commit aba3a18

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/parser/serializer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ function serializeInto(
786786
const type = typeof value;
787787

788788
// Check the key and throw error if it's illegal
789-
if (!ignoreKeys.has(key)) {
789+
if (typeof key === 'string' && !ignoreKeys.has(key)) {
790790
if (key.match(regexp) != null) {
791791
// The BSON spec doesn't allow keys with null bytes because keys are
792792
// null-terminated.
@@ -886,7 +886,7 @@ function serializeInto(
886886
const type = typeof value;
887887

888888
// Check the key and throw error if it's illegal
889-
if (!ignoreKeys.has(key)) {
889+
if (typeof key === 'string' && !ignoreKeys.has(key)) {
890890
if (key.match(regexp) != null) {
891891
// The BSON spec doesn't allow keys with null bytes because keys are
892892
// null-terminated.

0 commit comments

Comments
 (0)