Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($parse): support methods on falsy primitive types
Browse files Browse the repository at this point in the history
e.g. zero, false, empty string

- fix tests to be executed with csp true
- fix cps (when more than 5 parts)
  • Loading branch information
vojtajina committed May 5, 2012
1 parent 8e26750 commit 499a76a
Show file tree
Hide file tree
Showing 2 changed files with 402 additions and 384 deletions.
19 changes: 11 additions & 8 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope,
promise;

if (!pathVal) return pathVal;
if (pathVal === null || pathVal === undefined) return pathVal;

pathVal = pathVal[key0];
if (pathVal && pathVal.then) {
Expand All @@ -706,7 +706,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
}
pathVal = pathVal.$$v;
}
if (!key1 || !pathVal) return pathVal;
if (!key1 || pathVal === null || pathVal === undefined) return pathVal;

pathVal = pathVal[key1];
if (pathVal && pathVal.then) {
Expand All @@ -717,7 +717,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
}
pathVal = pathVal.$$v;
}
if (!key2 || !pathVal) return pathVal;
if (!key2 || pathVal === null || pathVal === undefined) return pathVal;

pathVal = pathVal[key2];
if (pathVal && pathVal.then) {
Expand All @@ -728,7 +728,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
}
pathVal = pathVal.$$v;
}
if (!key3 || !pathVal) return pathVal;
if (!key3 || pathVal === null || pathVal === undefined) return pathVal;

pathVal = pathVal[key3];
if (pathVal && pathVal.then) {
Expand All @@ -739,7 +739,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
}
pathVal = pathVal.$$v;
}
if (!key4 || !pathVal) return pathVal;
if (!key4 || pathVal === null || pathVal === undefined) return pathVal;

pathVal = pathVal[key4];
if (pathVal && pathVal.then) {
Expand Down Expand Up @@ -767,18 +767,21 @@ function getterFn(path, csp) {
fn = (pathKeysLength < 6)
? cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4])
: function(scope, locals) {
var i = 0, val;
var i = 0, val
do {
val = cspSafeGetterFn(
pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++]
)(scope, locals);

locals = undefined; // clear after first iteration
scope = val;
} while (i < pathKeysLength);
};
return val;
}
} else {
var code = 'var l, fn, p;\n';
forEach(pathKeys, function(key, index) {
code += 'if(!s) return s;\n' +
code += 'if(s === null || s === undefined) return s;\n' +
'l=s;\n' +
's='+ (index
// we simply dereference 's' on any .dot notation
Expand Down
Loading

0 comments on commit 499a76a

Please sign in to comment.