Skip to content

Commit 954a8a4

Browse files
authored
Better support for null values in arrays (#2777)
* Adds reproduction for #2752 * Make sure we support null values in arrays of pointers for inclusion
1 parent a60935d commit 954a8a4

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

spec/ParseObject.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,4 +1922,37 @@ describe('Parse.Object testing', () => {
19221922
done();
19231923
})
19241924
});
1925+
1926+
it('should handle includes on null arrays #2752', (done) => {
1927+
let obj1 = new Parse.Object("AnObject");
1928+
let obj2 = new Parse.Object("AnotherObject");
1929+
let obj3 = new Parse.Object("NestedObject");
1930+
obj3.set({
1931+
"foo": "bar"
1932+
})
1933+
obj2.set({
1934+
"key": obj3
1935+
})
1936+
1937+
Parse.Object.saveAll([obj1, obj2]).then(() => {
1938+
obj1.set("objects", [null, null, obj2]);
1939+
return obj1.save();
1940+
}).then(() => {
1941+
let query = new Parse.Query("AnObject");
1942+
query.include("objects.key");
1943+
return query.find();
1944+
}).then((res) => {
1945+
let obj = res[0];
1946+
expect(obj.get("objects")).not.toBe(undefined);
1947+
let array = obj.get("objects");
1948+
expect(Array.isArray(array)).toBe(true);
1949+
expect(array[0]).toBe(null);
1950+
expect(array[1]).toBe(null);
1951+
expect(array[2].get("key").get("foo")).toEqual("bar");
1952+
done();
1953+
}).catch(err => {
1954+
jfail(err);
1955+
done();
1956+
})
1957+
});
19251958
});

src/RestQuery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ function findPointers(object, path) {
555555
return answer;
556556
}
557557

558-
if (typeof object !== 'object') {
558+
if (typeof object !== 'object' || !object) {
559559
return [];
560560
}
561561

@@ -585,7 +585,7 @@ function replacePointers(object, path, replace) {
585585
.filter((obj) => typeof obj !== 'undefined');
586586
}
587587

588-
if (typeof object !== 'object') {
588+
if (typeof object !== 'object' || !object) {
589589
return object;
590590
}
591591

0 commit comments

Comments
 (0)