File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -691,6 +691,32 @@ describe('miscellaneous', function () {
691
691
) ;
692
692
} ) ;
693
693
694
+ it ( 'test afterSave with deeply nested keys (#7384)' , async ( ) => {
695
+ let triggerTime = 0 ;
696
+ Parse . Cloud . afterSave ( 'GameScore' , function ( req ) {
697
+ const object = req . object ;
698
+ expect ( object instanceof Parse . Object ) . toBeTruthy ( ) ;
699
+ if ( triggerTime == 0 ) {
700
+ // Create
701
+ expect ( object . get ( 'a' ) ) . toEqual ( { b : { c : 0 } } ) ;
702
+ } else if ( triggerTime == 1 ) {
703
+ // Update
704
+ expect ( object . get ( 'a' ) ) . toEqual ( { b : { c : 1 } } ) ;
705
+ } else {
706
+ throw new Error ( ) ;
707
+ }
708
+ triggerTime ++ ;
709
+ } ) ;
710
+
711
+ const obj = new Parse . Object ( 'GameScore' ) ;
712
+ obj . set ( 'a' , { b : { c : 0 } } ) ;
713
+ await obj . save ( ) ;
714
+ obj . set ( 'a.b.c' , 1 ) ;
715
+ await obj . save ( ) ;
716
+ // Make sure the checking has been triggered
717
+ expect ( triggerTime ) . toBe ( 2 ) ;
718
+ } ) ;
719
+
694
720
it ( 'test afterSave get original object on update' , function ( done ) {
695
721
let triggerTime = 0 ;
696
722
// Register a mock beforeSave hook
Original file line number Diff line number Diff line change @@ -1599,7 +1599,12 @@ RestWrite.prototype.buildUpdatedObject = function (extraData) {
1599
1599
if ( typeof parentVal !== 'object' ) {
1600
1600
parentVal = { } ;
1601
1601
}
1602
- parentVal [ splittedKey [ 1 ] ] = data [ key ] ;
1602
+ let curObj = parentVal ;
1603
+ for ( let i = 1 ; i < splittedKey . length - 1 ; i ++ ) {
1604
+ if ( typeof curObj [ splittedKey [ i ] ] === 'undefined' ) curObj [ splittedKey [ i ] ] = { } ;
1605
+ curObj = curObj [ splittedKey [ i ] ] ;
1606
+ }
1607
+ curObj [ splittedKey [ splittedKey . length - 1 ] ] = data [ key ] ;
1603
1608
updatedObject . set ( parentProp , parentVal ) ;
1604
1609
}
1605
1610
delete data [ key ] ;
You can’t perform that action at this time.
0 commit comments