Skip to content
Open
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
22 changes: 22 additions & 0 deletions spec/QueryTools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,28 @@ describe('matchesQuery', function () {
expect(matchesQuery(message, q)).toBe(false);
});

it('does not match or crash when a pointer field is null (#7929)', () => {
// Parse Dashboard stores a cleared pointer as null rather than unsetting it.
const message = {
id: new Id('Message', 'O1'),
profile: null,
};
const q = new Parse.Query('Message');
q.equalTo('profile', Parse.Object.fromJSON({ className: 'Profile', objectId: 'abc' }));
expect(matchesQuery(message, q)).toBe(false);
});

it('does not match or crash when a typed field is null (#7929)', () => {
// Same null-field scenario against a non-pointer typed constraint (goes through equalObjects).
const obj = {
id: new Id('Person', 'O1'),
birthday: null,
};
const q = new Parse.Query('Person');
q.equalTo('birthday', new Date(1990, 1));
expect(matchesQuery(obj, q)).toBe(false);
});

it('should support containedIn with array of pointers', () => {
const message = {
id: new Id('Message', 'O2'),
Expand Down
2 changes: 2 additions & 0 deletions src/LiveQuery/QueryTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ function matchesKeyConstraints(object, key, constraints) {
if (constraints.__type) {
if (constraints.__type === 'Pointer') {
return equalObjectsGeneric(object[key], constraints, function (obj, ptr) {
// A cleared pointer can be stored as null (e.g. via Parse Dashboard), guard it (#7929)
return (
typeof obj !== 'undefined' &&
obj !== null &&
ptr.className === obj.className &&
ptr.objectId === obj.objectId
);
Expand Down
4 changes: 4 additions & 0 deletions src/LiveQuery/equalObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function equalObjects(a, b) {
if (a === b) {
return true;
}
// typeof null is 'object', so guard before dereferencing either side (#7929)
if (a === null || b === null) {
return a === b;
}
if (toString.call(a) === '[object Date]') {
if (toString.call(b) === '[object Date]') {
return +a === +b;
Expand Down
Loading