Skip to content

Commit 8d8a8b2

Browse files
flovilmartnatanrolnik
authored andcommitted
Fixes issue affecting liveQuery on location null/undefined values (#4171)
1 parent d0184f4 commit 8d8a8b2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

spec/QueryTools.spec.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,16 @@ describe('matchesQuery', function() {
360360
id: new Id('Checkin', 'C1'),
361361
location: new Parse.GeoPoint(40, 40)
362362
};
363+
var ptUndefined = {
364+
id: new Id('Checkin', 'C1')
365+
};
366+
var ptNull = {
367+
id: new Id('Checkin', 'C1'),
368+
location: null
369+
};
363370
expect(matchesQuery(pt, q)).toBe(true);
371+
expect(matchesQuery(ptUndefined, q)).toBe(false);
372+
expect(matchesQuery(ptNull, q)).toBe(false);
364373

365374
q = new Parse.Query('Checkin');
366375
pt.location = new Parse.GeoPoint(40, 40);
@@ -384,6 +393,17 @@ describe('matchesQuery', function() {
384393
name: 'Santa Clara'
385394
};
386395

396+
var noLocation = {
397+
id: new Id('Checkin', 'C2'),
398+
name: 'Santa Clara'
399+
};
400+
401+
var nullLocation = {
402+
id: new Id('Checkin', 'C2'),
403+
location: null,
404+
name: 'Santa Clara'
405+
};
406+
387407
var q = new Parse.Query('Checkin').withinGeoBox(
388408
'location',
389409
new Parse.GeoPoint(37.708813, -122.526398),
@@ -392,7 +412,8 @@ describe('matchesQuery', function() {
392412

393413
expect(matchesQuery(caltrainStation, q)).toBe(true);
394414
expect(matchesQuery(santaClara, q)).toBe(false);
395-
415+
expect(matchesQuery(noLocation, q)).toBe(false);
416+
expect(matchesQuery(nullLocation, q)).toBe(false);
396417
// Invalid rectangles
397418
q = new Parse.Query('Checkin').withinGeoBox(
398419
'location',

src/LiveQuery/QueryTools.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,16 @@ function matchesKeyConstraints(object, key, constraints) {
262262
}
263263
break;
264264
case '$nearSphere':
265+
if (!compareTo || !object[key]) {
266+
return false;
267+
}
265268
var distance = compareTo.radiansTo(object[key]);
266269
var max = constraints.$maxDistance || Infinity;
267270
return distance <= max;
268271
case '$within':
272+
if (!compareTo || !object[key]) {
273+
return false;
274+
}
269275
var southWest = compareTo.$box[0];
270276
var northEast = compareTo.$box[1];
271277
if (southWest.latitude > northEast.latitude ||

0 commit comments

Comments
 (0)