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

Commit 499a76a

Browse files
committed
fix($parse): support methods on falsy primitive types
e.g. zero, false, empty string - fix tests to be executed with csp true - fix cps (when more than 5 parts)
1 parent 8e26750 commit 499a76a

File tree

2 files changed

+402
-384
lines changed

2 files changed

+402
-384
lines changed

src/ng/parse.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
695695
var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope,
696696
promise;
697697

698-
if (!pathVal) return pathVal;
698+
if (pathVal === null || pathVal === undefined) return pathVal;
699699

700700
pathVal = pathVal[key0];
701701
if (pathVal && pathVal.then) {
@@ -706,7 +706,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
706706
}
707707
pathVal = pathVal.$$v;
708708
}
709-
if (!key1 || !pathVal) return pathVal;
709+
if (!key1 || pathVal === null || pathVal === undefined) return pathVal;
710710

711711
pathVal = pathVal[key1];
712712
if (pathVal && pathVal.then) {
@@ -717,7 +717,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
717717
}
718718
pathVal = pathVal.$$v;
719719
}
720-
if (!key2 || !pathVal) return pathVal;
720+
if (!key2 || pathVal === null || pathVal === undefined) return pathVal;
721721

722722
pathVal = pathVal[key2];
723723
if (pathVal && pathVal.then) {
@@ -728,7 +728,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
728728
}
729729
pathVal = pathVal.$$v;
730730
}
731-
if (!key3 || !pathVal) return pathVal;
731+
if (!key3 || pathVal === null || pathVal === undefined) return pathVal;
732732

733733
pathVal = pathVal[key3];
734734
if (pathVal && pathVal.then) {
@@ -739,7 +739,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4) {
739739
}
740740
pathVal = pathVal.$$v;
741741
}
742-
if (!key4 || !pathVal) return pathVal;
742+
if (!key4 || pathVal === null || pathVal === undefined) return pathVal;
743743

744744
pathVal = pathVal[key4];
745745
if (pathVal && pathVal.then) {
@@ -767,18 +767,21 @@ function getterFn(path, csp) {
767767
fn = (pathKeysLength < 6)
768768
? cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4])
769769
: function(scope, locals) {
770-
var i = 0, val;
770+
var i = 0, val
771771
do {
772772
val = cspSafeGetterFn(
773773
pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++]
774774
)(scope, locals);
775+
775776
locals = undefined; // clear after first iteration
777+
scope = val;
776778
} while (i < pathKeysLength);
777-
};
779+
return val;
780+
}
778781
} else {
779782
var code = 'var l, fn, p;\n';
780783
forEach(pathKeys, function(key, index) {
781-
code += 'if(!s) return s;\n' +
784+
code += 'if(s === null || s === undefined) return s;\n' +
782785
'l=s;\n' +
783786
's='+ (index
784787
// we simply dereference 's' on any .dot notation

0 commit comments

Comments
 (0)