Skip to content

Commit d5b1cce

Browse files
committed
fix(beforeSave): Return value instead of Parse.Op
1 parent a4c84c0 commit d5b1cce

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

spec/CloudCode.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,8 +1481,9 @@ describe('Cloud Code', () => {
14811481

14821482
it('beforeSave should not sanitize database', async done => {
14831483
let count = 0;
1484-
Parse.Cloud.beforeSave('CloudIncrementNested', () => {
1484+
Parse.Cloud.beforeSave('CloudIncrementNested', req => {
14851485
count += 1;
1486+
expect(typeof req.object.get('objectField').number).toBe('number');
14861487
});
14871488

14881489
const obj = new Parse.Object('CloudIncrementNested');

src/RestWrite.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,15 +1558,19 @@ RestWrite.prototype.buildUpdatedObject = function (extraData) {
15581558
const updatedObject = triggers.inflate(extraData, this.originalData);
15591559
Object.keys(this.data).reduce(function (data, key) {
15601560
if (key.indexOf('.') > 0) {
1561-
// subdocument key with dot notation ('x.y':v => 'x':{'y':v})
1562-
const splittedKey = key.split('.');
1563-
const parentProp = splittedKey[0];
1564-
let parentVal = updatedObject.get(parentProp);
1565-
if (typeof parentVal !== 'object') {
1566-
parentVal = {};
1561+
if (typeof data[key].__op === 'string') {
1562+
updatedObject.set(key, data[key]);
1563+
} else {
1564+
// subdocument key with dot notation { 'x.y': v } => { 'x': { 'y' : v } })
1565+
const splittedKey = key.split('.');
1566+
const parentProp = splittedKey[0];
1567+
let parentVal = updatedObject.get(parentProp);
1568+
if (typeof parentVal !== 'object') {
1569+
parentVal = {};
1570+
}
1571+
parentVal[splittedKey[1]] = data[key];
1572+
updatedObject.set(parentProp, parentVal);
15671573
}
1568-
parentVal[splittedKey[1]] = data[key];
1569-
updatedObject.set(parentProp, parentVal);
15701574
delete data[key];
15711575
}
15721576
return data;

0 commit comments

Comments
 (0)