Fix null pointer includes (#2657)
* Adds failing test for #2189 * Improves support for null values in includes * nit
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
@@ -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 [];
|
||||
@@ -564,7 +567,7 @@ 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') {
|
||||
@@ -572,7 +575,7 @@ function replacePointers(object, path, replace) {
|
||||
}
|
||||
|
||||
if (path.length === 0) {
|
||||
if (object.__type === 'Pointer') {
|
||||
if (object && object.__type === 'Pointer') {
|
||||
return replace[object.objectId];
|
||||
}
|
||||
return object;
|
||||
|
||||
Reference in New Issue
Block a user