From bfdc87803003e97e15063a27606d6c35b89133be Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 11 Nov 2020 14:13:40 -0600 Subject: [PATCH 1/2] fix(beforeSave): Skip Sanitizing Database results --- spec/CloudCode.spec.js | 17 +++++++++++++++++ src/RestWrite.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index 995d09b6cc..f8a8156b77 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -1479,6 +1479,23 @@ describe('Cloud Code', () => { }); }); + it('beforeSave should not sanitize database', async done => { + let count = 0; + Parse.Cloud.beforeSave('CloudIncrementNested', () => { + count += 1; + if (count === 2) { + done(); + } + }); + + const obj = new Parse.Object('CloudIncrementNested'); + obj.set('objectField', { number: 5 }); + await obj.save(); + + obj.increment('objectField.number', 10); + await obj.save(); + }); + /** * Verifies that an afterSave hook throwing an exception * will not prevent a successful save response from being returned diff --git a/src/RestWrite.js b/src/RestWrite.js index 0825267eeb..9467c6a2d1 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -235,7 +235,7 @@ RestWrite.prototype.runBeforeSaveTrigger = function () { this.query, this.data, this.runOptions, - false, + true, true ); } else { From 2b7534d231d36bbdc6b09f13e5f904f3586b7b4b Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 11 Nov 2020 14:32:38 -0600 Subject: [PATCH 2/2] fix test --- spec/CloudCode.spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index f8a8156b77..e60b6db491 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -1483,9 +1483,6 @@ describe('Cloud Code', () => { let count = 0; Parse.Cloud.beforeSave('CloudIncrementNested', () => { count += 1; - if (count === 2) { - done(); - } }); const obj = new Parse.Object('CloudIncrementNested'); @@ -1494,6 +1491,7 @@ describe('Cloud Code', () => { obj.increment('objectField.number', 10); await obj.save(); + count === 2 ? done() : fail(); }); /**