From 2d1eee27f915e1758b348bb208777d6e7f783464 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 6 Sep 2016 10:33:25 -0400 Subject: [PATCH 1/3] Adds failing test for #2189 --- spec/RestQuery.spec.js | 32 ++++++++++++++++++++++++++++++++ src/RestQuery.js | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/spec/RestQuery.spec.js b/spec/RestQuery.spec.js index 9e2b775922..2aa5add447 100644 --- a/spec/RestQuery.spec.js +++ b/spec/RestQuery.spec.js @@ -235,4 +235,36 @@ describe('rest query', () => { done(); }); }); + + it('makes sure null pointers are handed correctly #2189', done => { + let object = new Parse.Object('AnObject'); + let anotherObject = new Parse.Object('AnotherObject'); + anotherObject.save().then(() => { + object.set('values', [null, null, anotherObject]); + return object.save(); + }).then(() => { + let query = new Parse.Query('AnObject'); + query.include('values'); + return query.first(); + }).then((result) => { + let values = result.get('values'); + expect(values.length).toBe(3); + let anotherObjectFound = false; + let nullCounts = 0; + for(let value of values) { + if (value === null) { + nullCounts++; + } else if (value instanceof Parse.Object) { + anotherObjectFound = true; + } + } + expect(nullCounts).toBe(2); + expect(anotherObjectFound).toBeTruthy(); + done(); + }, (err) => { + console.error(err); + fail(err); + done(); + }); + }); }); diff --git a/src/RestQuery.js b/src/RestQuery.js index 0dc95ff341..6fd1e68e18 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -542,7 +542,7 @@ function findPointers(object, path) { } if (path.length == 0) { - if (object.__type == 'Pointer') { + if (object === null || object.__type == 'Pointer') { return [object]; } return []; @@ -567,7 +567,7 @@ function replacePointers(object, path, replace) { .filter((obj) => obj != null && obj != undefined); } - if (typeof object !== 'object') { + if (typeof object !== 'object' || object === null) { return object; } From ed784e24e0c0a38a6c2e1a158028d975a34c8fe6 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 6 Sep 2016 09:43:42 -0400 Subject: [PATCH 2/3] Improves support for null values in includes --- src/RestQuery.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/RestQuery.js b/src/RestQuery.js index 6fd1e68e18..b3f01a484f 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -480,6 +480,9 @@ function includePath(config, auth, response, path) { let pointersHash = {}; var objectIds = {}; for (var pointer of pointers) { + if (!pointer) { + continue; + } let className = pointer.className; // only include the good pointers if (className) { @@ -537,7 +540,7 @@ function findPointers(object, path) { return answer; } - if (typeof object !== 'object') { + if (typeof object !== 'object' || object === null) { return []; } @@ -564,15 +567,15 @@ function findPointers(object, path) { function replacePointers(object, path, replace) { if (object instanceof Array) { return object.map((obj) => replacePointers(obj, path, replace)) - .filter((obj) => obj != null && obj != undefined); + .filter((obj) => typeof obj !== 'undefined'); } - if (typeof object !== 'object' || object === null) { + if (typeof object !== 'object') { return object; } if (path.length === 0) { - if (object.__type === 'Pointer') { + if (object && object.__type === 'Pointer') { return replace[object.objectId]; } return object; From e769e2b28fd819efaa7b6fd3d1d8461b2b539a8b Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 6 Sep 2016 15:39:20 -0400 Subject: [PATCH 3/3] nit --- src/RestQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RestQuery.js b/src/RestQuery.js index b3f01a484f..6752436c54 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -540,7 +540,7 @@ function findPointers(object, path) { return answer; } - if (typeof object !== 'object' || object === null) { + if (typeof object !== 'object') { return []; }