Skip to content

Commit

Permalink
Merge pull request #881 from stephenplusplus/spp--datastore-multiple-…
Browse files Browse the repository at this point in the history
…entities

datastore: prevent manipulating user input during save
  • Loading branch information
callmehiphop committed Sep 21, 2015
2 parents 8d24946 + 5695ba2 commit 5df7951
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ DatastoreRequest.prototype.save = function(entities, callback) {

var req = {
mutation: entities.reduce(function(acc, entityObject, index) {
entityObject = extend(true, {}, entityObject);

var ent = {};
var method = entityObject.method;
delete entityObject.method;
Expand Down
26 changes: 26 additions & 0 deletions test/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,32 @@ describe('Request', function() {
], done);
});

it('should not alter the provided data object', function(done) {
var entities = [
{
key: key,
method: 'insert',
indexed: false,
data: {
value: {
a: 'b',
c: [1, 2, 3]
}
}
}
];
var expectedEntities = extend(true, {}, entities);

request.makeReq_ = function() {
// By the time the request is made, the original object has already been
// transformed into a raw request.
assert.deepEqual(entities, expectedEntities);
done();
};

request.save(entities, assert.ifError);
});

it('should return apiResponse in callback', function(done) {
var key = new entity.Key({ namespace: 'ns', path: ['Company'] });
var mockCommitResponse = {
Expand Down

0 comments on commit 5df7951

Please sign in to comment.