From d13b4bd1f5f2abaad00f5d1bf81f79549a8d0e46 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Fri, 12 Sep 2014 08:25:41 -0400 Subject: [PATCH] fix($parse): ensure CSP assignable expressions have `assign()` Fixes regression where the `assign()` method was not added to chains of identifiers in CSP mode, introduced originally in b3b476d. Also fixes the $parse test suite to ensure that CSP code paths are taken when they're expected to be taken. Closes #9048 --- src/ng/parse.js | 8 ++++---- test/ng/parseSpec.js | 19 ++++++------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index ae87928f..d09cc516 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -898,7 +898,7 @@ function getterFn(path, options, fullExp) { if (pathKeysLength < 6) { fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp); } else { - fn = function(scope, locals) { + fn = function cspSafeGetter(scope, locals) { var i = 0, val; do { val = cspSafeGetterFn(pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], @@ -927,14 +927,14 @@ function getterFn(path, options, fullExp) { var evaledFnGetter = new Function('s', 'l', code); // s=scope, l=locals /* jshint +W054 */ evaledFnGetter.toString = valueFn(code); - evaledFnGetter.assign = function(self, value) { - return setter(self, path, value, path); - }; fn = evaledFnGetter; } fn.sharedGetter = true; + fn.assign = function(self, value) { + return setter(self, path, value, path); + }; getterFnCache[path] = fn; return fn; } diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 618149ce..122422d4 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -210,19 +210,12 @@ describe('parser', function() { forEach([true, false], function(cspEnabled) { describe('csp: ' + cspEnabled, function() { - var originalSecurityPolicy; - - - beforeEach(function() { - originalSecurityPolicy = window.document.securityPolicy; - window.document.securityPolicy = {isActive : cspEnabled}; - }); - - afterEach(function() { - window.document.securityPolicy = originalSecurityPolicy; - }); - - beforeEach(module(provideLog)); + beforeEach(module(function($provide) { + $provide.decorator('$sniffer', function($delegate) { + $delegate.csp = cspEnabled; + return $delegate; + }); + }, provideLog)); beforeEach(inject(function ($rootScope) { scope = $rootScope;