Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions spec/RestQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
9 changes: 6 additions & 3 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -542,7 +545,7 @@ function findPointers(object, path) {
}

if (path.length == 0) {
if (object.__type == 'Pointer') {
if (object === null || object.__type == 'Pointer') {
return [object];
}
return [];
Expand All @@ -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');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strip out undefined, and keep the nulls to match parse.com behaviour

}

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;
Expand Down