From b9f08d9694cf9ee2f648de999a9c9a44dbfea4b4 Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Tue, 8 Mar 2016 16:08:41 -0800 Subject: [PATCH] Do not mutate parameter object in DatabaseController. --- src/Controllers/DatabaseController.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index f261db56..80eea63b 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -6,6 +6,7 @@ var Parse = require('parse/node').Parse; var Schema = require('./../Schema'); var transform = require('./../transform'); +const deepcopy = require('deepcopy'); // options can contain: // collectionPrefix: the string to put in front of every collection name. @@ -130,6 +131,9 @@ DatabaseController.prototype.untransformObject = function( // one of the provided strings must provide the caller with // write permissions. DatabaseController.prototype.update = function(className, query, update, options) { + // Make a copy of the object, so we don't mutate the incoming data. + update = deepcopy(update); + var acceptor = function(schema) { return schema.hasKeys(className, Object.keys(query)); }; @@ -300,6 +304,9 @@ DatabaseController.prototype.destroy = function(className, query, options = {}) // Inserts an object into the database. // Returns a promise that resolves successfully iff the object saved. DatabaseController.prototype.create = function(className, object, options) { + // Make a copy of the object, so we don't mutate the incoming data. + object = deepcopy(object); + var schema; var isMaster = !('acl' in options); var aclGroup = options.acl || [];