File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -373,7 +373,7 @@ export default class ParseObject {
373373 if ( ( attr === 'createdAt' || attr === 'updatedAt' ) && attrs [ attr ] . toJSON ) {
374374 json [ attr ] = attrs [ attr ] . toJSON ( ) ;
375375 } else {
376- json [ attr ] = encode ( attrs [ attr ] , false , false ) ;
376+ json [ attr ] = encode ( attrs [ attr ] , false , true ) ;
377377 }
378378 }
379379 var pending = this . _getPendingOps ( ) ;
Original file line number Diff line number Diff line change @@ -523,6 +523,47 @@ describe('ParseObject', () => {
523523 expect ( o2 . get ( 'age' ) ) . toBe ( 22 ) ;
524524 } ) ;
525525
526+ it ( 'does not stack-overflow when encoding recursive pointers' , ( ) => {
527+ var o = ParseObject . fromJSON ( {
528+ __type : 'Object' ,
529+ className : 'Item' ,
530+ objectId : 'recurParent' ,
531+ child : {
532+ __type : 'Pointer' ,
533+ className : 'Item' ,
534+ objectId : 'recurChild'
535+ }
536+ } ) ;
537+ expect ( o . toJSON ( ) ) . toEqual ( {
538+ objectId : 'recurParent' ,
539+ child : {
540+ __type : 'Pointer' ,
541+ className : 'Item' ,
542+ objectId : 'recurChild'
543+ }
544+ } ) ;
545+
546+ var child = ParseObject . fromJSON ( {
547+ __type : 'Object' ,
548+ className : 'Item' ,
549+ objectId : 'recurChild' ,
550+ parent : {
551+ __type : 'Pointer' ,
552+ className : 'Item' ,
553+ objectId : 'recurParent'
554+ }
555+ } ) ;
556+
557+ expect ( o . toJSON ( ) ) . toEqual ( {
558+ objectId : 'recurParent' ,
559+ child : {
560+ __type : 'Pointer' ,
561+ className : 'Item' ,
562+ objectId : 'recurChild'
563+ }
564+ } ) ;
565+ } ) ;
566+
526567 it ( 'updates the existed flag when saved' , ( ) => {
527568 var o = new ParseObject ( 'Item' ) ;
528569 expect ( o . existed ( ) ) . toBe ( false ) ;
You can’t perform that action at this time.
0 commit comments