Skip to content

Commit

Permalink
Merge pull request #162 from canjs/get-paths-booleans
Browse files Browse the repository at this point in the history
preventing in operator errors if scope._context is not an object
  • Loading branch information
phillipskevin committed May 15, 2018
2 parents 708381c + 9a70b5c commit 16d8a3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion can-view-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ assign(Scope.prototype, {
// `notContext` and `special` contexts can't be read using `../`
var canBeRead = !scope._meta.special && !scope._meta.notContext;

if (canBeRead && canReflect.hasKey(scope._context, normalizedKey)) {
if (canBeRead && typeof scope._context === "object" && canReflect.hasKey(scope._context, normalizedKey)) {
paths[cur + normalizedKey] = scope._context;
}

Expand Down
5 changes: 3 additions & 2 deletions test/scope-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ QUnit.test("scope.getPathsForKey", function() {
.add(notContext, { notContext: true })
.add(vm, { viewModel: true })
.add(special, { special: true })
.add(true)
.add(nonVm);

var paths = scope.getPathsForKey("name");
Expand All @@ -1304,7 +1305,7 @@ QUnit.test("scope.getPathsForKey", function() {
"scope.vm.name": vm,
"scope.top.name": top,
"name": nonVm,
"../../name": vm,
"../../../../name": top
"../../../name": vm,
"../../../../../name": top
});
});

0 comments on commit 16d8a3b

Please sign in to comment.