mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Disallow mixed modifier/non-modifier fields in updates
We expect modifiers to be either modifiers or replacements, not a mix. MongoDB does this check also, but do it in meteor too as a safety belt.
This commit is contained in:
committed by
David Glasser
parent
d9feb32148
commit
d700610397
@@ -514,10 +514,20 @@ MongoConnection.prototype._update = function (collection_name, selector, mod,
|
||||
};
|
||||
|
||||
var isModificationMod = function (mod) {
|
||||
for (var k in mod)
|
||||
if (k.substr(0, 1) === '$')
|
||||
return true;
|
||||
return false;
|
||||
var isReplace = false;
|
||||
var isModify = false;
|
||||
for (var k in mod) {
|
||||
if (k.substr(0, 1) === '$') {
|
||||
isModify = true;
|
||||
} else {
|
||||
isReplace = true;
|
||||
}
|
||||
}
|
||||
if (isModify && isReplace) {
|
||||
throw new Error(
|
||||
"Update parameter cannot have both modifier and non-modifier fields.");
|
||||
}
|
||||
return isModify;
|
||||
};
|
||||
|
||||
var NUM_OPTIMISTIC_TRIES = 3;
|
||||
|
||||
@@ -3068,7 +3068,7 @@ Meteor.isServer && testAsyncMulti("mongo-livedata - update with replace forbidde
|
||||
|
||||
test.throws(function () {
|
||||
c.update(id, { foo3: "bar3", $set: { blah: 1 } });
|
||||
}, "cannot be mixed");
|
||||
}, "cannot have both modifier and non-modifier fields");
|
||||
test.equal(c.findOne(id), { _id: id, foo2: "bar2" });
|
||||
}
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user