Skip to content

Commit

Permalink
fix(serializer): do not use checkKeys for $clusterTime
Browse files Browse the repository at this point in the history
Fixes NODE-1409

* 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
  • Loading branch information
kvwalker authored Aug 8, 2018
1 parent 7656804 commit 573e141
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/bson/parser/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var normalizedFunctionString = require('./utils').normalizedFunctionString;
// }

var regexp = /\x00/; // eslint-disable-line no-control-regex
var ignoreKeys = ['$db', '$ref', '$id', '$clusterTime'];

// To ensure that 0.4 of node works correctly
var isDate = function isDate(d) {
Expand Down Expand Up @@ -798,7 +799,7 @@ var serializeInto = function serializeInto(
type = typeof value;

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

// Check the key and throw error if it's illegal
if (key !== '$db' && key !== '$ref' && key !== '$id') {
if (typeof key === 'string' && ignoreKeys.indexOf(key) === -1) {
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 573e141

Please sign in to comment.