Skip to content

Commit

Permalink
Merge pull request #896 from blaky/null-check-dot-sub-scan
Browse files Browse the repository at this point in the history
added missing null check to dot sub scan fixes #891
  • Loading branch information
techfort authored Mar 28, 2022
2 parents 1f414a5 + cdebfea commit 25b9a33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions spec/generic/ops.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,17 @@ describe("Individual operator tests", function() {
expect(coll.find({ "c": { $eq: undefined } }).length).toEqual(4);
});

it('query nested documents with nullable object', function() {
var db = new loki('db');
var coll = db.addCollection('coll');

coll.insert({ a: null, b: 5, c: { a: 1 }});
coll.insert({ a: "11", b: 5, c: { a: 1 }});
coll.insert({ a: "11", b: 5, c: null});

expect(coll.find({ "c.a": { $eq: 1 } }).length).toEqual(2);
});

it('$exists ops work as expected', function() {
var db = new loki('db');
var coll = db.addCollection('coll');
Expand Down
2 changes: 1 addition & 1 deletion src/lokijs.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@

var valueFound = false;
var element;
if (typeof root === 'object' && path in root) {
if (root !== null && typeof root === 'object' && path in root) {
element = root[path];
}
if (pathOffset + 1 >= paths.length) {
Expand Down

0 comments on commit 25b9a33

Please sign in to comment.