Disallow EJSON custom types as replacement documents in updates

This commit is contained in:
Emily Stark
2014-12-16 13:16:34 -08:00
parent 7461cab726
commit a16d0cb71a
2 changed files with 16 additions and 1 deletions

View File

@@ -320,7 +320,7 @@ MongoConnection.prototype._insert = function (collection_name, document,
if (!(LocalCollection._isPlainObject(document) &&
!EJSON._isCustomType(document))) {
sendError(new Error(
"Only documents (plain objects) may be inserted into MongoDB"));
"Only plain objects may be inserted into MongoDB"));
return;
}
@@ -432,6 +432,14 @@ MongoConnection.prototype._update = function (collection_name, selector, mod,
if (!mod || typeof mod !== 'object')
throw new Error("Invalid modifier. Modifier must be an object.");
if (!(LocalCollection._isPlainObject(mod) &&
!EJSON._isCustomType(mod))) {
throw new Error(
"Only plain objects may be used as replacement" +
" documents in MongoDB");
return;
}
if (!options) options = {};
var write = self._maybeBeginWrite();

View File

@@ -1481,6 +1481,7 @@ testAsyncMulti('mongo-livedata - document with a custom type, ' + idGeneration,
test.isFalse(err);
test.isTrue(id);
docId = id;
self.docId = docId;
var cursor = self.coll.find();
test.equal(cursor.count(), 1);
var inColl = self.coll.findOne();
@@ -1493,6 +1494,12 @@ testAsyncMulti('mongo-livedata - document with a custom type, ' + idGeneration,
test.isTrue(err);
test.isFalse(id);
}));
}, function (test, expect) {
var self = this;
self.coll.update(
self.docId, new Dog("rover", "orange"), expect(function (err) {
test.isTrue(err);
}));
}
]);