Skip to content

Commit 25b9a33

Browse files
authored
Merge pull request #896 from blaky/null-check-dot-sub-scan
added missing null check to dot sub scan fixes #891
2 parents 1f414a5 + cdebfea commit 25b9a33

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spec/generic/ops.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,17 @@ describe("Individual operator tests", function() {
359359
expect(coll.find({ "c": { $eq: undefined } }).length).toEqual(4);
360360
});
361361

362+
it('query nested documents with nullable object', function() {
363+
var db = new loki('db');
364+
var coll = db.addCollection('coll');
365+
366+
coll.insert({ a: null, b: 5, c: { a: 1 }});
367+
coll.insert({ a: "11", b: 5, c: { a: 1 }});
368+
coll.insert({ a: "11", b: 5, c: null});
369+
370+
expect(coll.find({ "c.a": { $eq: 1 } }).length).toEqual(2);
371+
});
372+
362373
it('$exists ops work as expected', function() {
363374
var db = new loki('db');
364375
var coll = db.addCollection('coll');

src/lokijs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@
415415

416416
var valueFound = false;
417417
var element;
418-
if (typeof root === 'object' && path in root) {
418+
if (root !== null && typeof root === 'object' && path in root) {
419419
element = root[path];
420420
}
421421
if (pathOffset + 1 >= paths.length) {

0 commit comments

Comments
 (0)