Fix null pointer includes (#2657)

* Adds failing test for #2189

* Improves support for null values in includes

* nit
This commit is contained in:
Florent Vilmart
2016-09-09 14:41:21 -04:00
committed by GitHub
parent fc576cb415
commit e8aa1ad312
2 changed files with 38 additions and 3 deletions

View File

@@ -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;