From e79d18b2d05b74430bdd410846da263a239596bf Mon Sep 17 00:00:00 2001 From: Robbie Pitts Date: Mon, 9 May 2016 14:29:01 -0400 Subject: [PATCH] Prevent ungettable objects from getting gotten during path lookup (#13461) Prevent ungettable objects from getting gotten during path lookup --- packages/ember-metal/lib/property_get.js | 16 +++++++++++++++- .../ember-metal/tests/accessors/get_path_test.js | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/ember-metal/lib/property_get.js b/packages/ember-metal/lib/property_get.js index 07920527ee8..37cac051195 100644 --- a/packages/ember-metal/lib/property_get.js +++ b/packages/ember-metal/lib/property_get.js @@ -5,6 +5,12 @@ import { assert } from 'ember-metal/debug'; import { isPath, hasThis } from 'ember-metal/path_cache'; +const ALLOWABLE_TYPES = { + object: true, + function: true, + string: true +}; + // .......................................................... // GET AND SET // @@ -75,7 +81,7 @@ export function _getPath(root, path) { let parts = path.split('.'); for (let i = 0; i < parts.length; i++) { - if (obj == null) { + if (!isGettable(obj)) { return undefined; } @@ -89,6 +95,14 @@ export function _getPath(root, path) { return obj; } +function isGettable(obj) { + if (obj == null) { + return false; + } + + return ALLOWABLE_TYPES[typeof obj]; +} + /** Retrieves the value of a property from an Object, or a default value in the case that the property returns `undefined`. diff --git a/packages/ember-metal/tests/accessors/get_path_test.js b/packages/ember-metal/tests/accessors/get_path_test.js index 80a867a1b21..19df6d3f2be 100644 --- a/packages/ember-metal/tests/accessors/get_path_test.js +++ b/packages/ember-metal/tests/accessors/get_path_test.js @@ -51,7 +51,7 @@ QUnit.test('[obj, falseValue.notDefined] -> (undefined)', function() { }); QUnit.test('[obj, emptyString.length] -> 0', function() { - equal(get(obj, 'emptyString.length'), 0); + strictEqual(get(obj, 'emptyString.length'), 0); }); QUnit.test('[obj, nullValue.notDefined] -> (undefined)', function() {