From 9a70b5c39b0940ecbc485e46f20829d3131deb67 Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Mon, 14 May 2018 22:01:30 -0500 Subject: [PATCH] preventing in operator errors if scope._context is not an object --- can-view-scope.js | 2 +- test/scope-test.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/can-view-scope.js b/can-view-scope.js index 3442507..ff912b4 100644 --- a/can-view-scope.js +++ b/can-view-scope.js @@ -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; } diff --git a/test/scope-test.js b/test/scope-test.js index 2da603b..3d3f2d2 100644 --- a/test/scope-test.js +++ b/test/scope-test.js @@ -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"); @@ -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 }); });