diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bd81b3fe8..9ef7d9e2c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -134,6 +134,7 @@ ___ - Add NPM package-lock version check to CI (Manuel Trezza) [#7333](https://github.com/parse-community/parse-server/pull/7333) - Fix incorrect LiveQuery events triggered for multiple subscriptions on the same class with different events [#7341](https://github.com/parse-community/parse-server/pull/7341) - Fix select and excludeKey queries to properly accept JSON string arrays. Also allow nested fields in exclude (Corey Baker) [#7242](https://github.com/parse-community/parse-server/pull/7242) +- Fix LiveQuery server crash when using $all query operator on a missing object key (Jason Posthuma) [#7421](https://github.com/parse-community/parse-server/pull/7421) ___ ## 4.5.0 diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index de4772a61c..7e09078dad 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -313,6 +313,16 @@ describe('matchesQuery', function () { expect(matchesQuery(player, orQuery)).toBe(true); }); + it('does not match $all query when value is missing', () => { + const player = { + id: new Id('Player', 'P1'), + name: 'Player 1', + score: 12, + }; + const q = { missing: { $all: [1, 2, 3] } }; + expect(matchesQuery(player, q)).toBe(false); + }); + it('matches an $and query', () => { const player = { id: new Id('Player', 'P1'), diff --git a/src/LiveQuery/QueryTools.js b/src/LiveQuery/QueryTools.js index 735788218b..905919ef61 100644 --- a/src/LiveQuery/QueryTools.js +++ b/src/LiveQuery/QueryTools.js @@ -253,6 +253,9 @@ function matchesKeyConstraints(object, key, constraints) { } break; case '$all': + if (!object[key]) { + return false; + } for (i = 0; i < compareTo.length; i++) { if (object[key].indexOf(compareTo[i]) < 0) { return false;