Skip to content

Commit

Permalink
Prevent ungettable objects from getting gotten during path lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie Pitts committed May 9, 2016
1 parent 82be117 commit 6bc3b62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/ember-metal/lib/property_get.js
Expand Up @@ -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
//
Expand Down Expand Up @@ -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;
}

Expand All @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-metal/tests/accessors/get_path_test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 6bc3b62

Please sign in to comment.