From 3b1a4fe0c83c7898ecd7261ab4213998ee7be0ec Mon Sep 17 00:00:00 2001 From: Brian Nenninger Date: Thu, 2 Jan 2014 00:42:59 -0500 Subject: fix($parse): fix CSP nested property evaluation, and issue that prevented its tests from failing cspSafeGetterFn incorrectly returned undefined if any of its key parameters were undefined. This wasn't caught by the $parse unit tests because of a timing problem where $ParseProvider was reading the CSP flag before the tests manually set it, so the CSP property evaluation tests never ran. Add test that verifies evaluation of nested properties of multiple lengths. Closes #5591 Closes #5592 --- src/ng/parse.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/ng/parse.js') diff --git a/src/ng/parse.js b/src/ng/parse.js index 28abe69e..1bd9b0e4 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -894,16 +894,20 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { if (pathVal == null) return pathVal; pathVal = pathVal[key0]; - if (pathVal == null) return key1 ? undefined : pathVal; + if (!key1) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key1]; - if (pathVal == null) return key2 ? undefined : pathVal; + if (!key2) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key2]; - if (pathVal == null) return key3 ? undefined : pathVal; + if (!key3) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key3]; - if (pathVal == null) return key4 ? undefined : pathVal; + if (!key4) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key4]; return pathVal; @@ -924,8 +928,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { } pathVal = pathVal.$$v; } - if (pathVal == null) return key1 ? undefined : pathVal; + if (!key1) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key1]; if (pathVal && pathVal.then) { promiseWarning(fullExp); @@ -936,8 +941,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { } pathVal = pathVal.$$v; } - if (pathVal == null) return key2 ? undefined : pathVal; + if (!key2) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key2]; if (pathVal && pathVal.then) { promiseWarning(fullExp); @@ -948,8 +954,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { } pathVal = pathVal.$$v; } - if (pathVal == null) return key3 ? undefined : pathVal; + if (!key3) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key3]; if (pathVal && pathVal.then) { promiseWarning(fullExp); @@ -960,8 +967,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { } pathVal = pathVal.$$v; } - if (pathVal == null) return key4 ? undefined : pathVal; + if (!key4) return pathVal; + if (pathVal == null) return undefined; pathVal = pathVal[key4]; if (pathVal && pathVal.then) { promiseWarning(fullExp); -- cgit v1.2.3