Skip to content

Commit

Permalink
fix(serializer): map insert expects only string keys
Browse files Browse the repository at this point in the history
Checks that the key is a string before checking that
the key is a valid string to prevent type error.

Fixes NODE-1572
  • Loading branch information
Sophie Saskin authored Aug 8, 2018
1 parent cbb4724 commit aba3a18
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/parser/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ function serializeInto(
const type = typeof value;

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

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

0 comments on commit aba3a18

Please sign in to comment.