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

Commit d13b4bd

Browse files
committed
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
1 parent c1f2c3e commit d13b4bd

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/ng/parse.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ function getterFn(path, options, fullExp) {
898898
if (pathKeysLength < 6) {
899899
fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp);
900900
} else {
901-
fn = function(scope, locals) {
901+
fn = function cspSafeGetter(scope, locals) {
902902
var i = 0, val;
903903
do {
904904
val = cspSafeGetterFn(pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++],
@@ -927,14 +927,14 @@ function getterFn(path, options, fullExp) {
927927
var evaledFnGetter = new Function('s', 'l', code); // s=scope, l=locals
928928
/* jshint +W054 */
929929
evaledFnGetter.toString = valueFn(code);
930-
evaledFnGetter.assign = function(self, value) {
931-
return setter(self, path, value, path);
932-
};
933930

934931
fn = evaledFnGetter;
935932
}
936933

937934
fn.sharedGetter = true;
935+
fn.assign = function(self, value) {
936+
return setter(self, path, value, path);
937+
};
938938
getterFnCache[path] = fn;
939939
return fn;
940940
}

test/ng/parseSpec.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,12 @@ describe('parser', function() {
210210
forEach([true, false], function(cspEnabled) {
211211
describe('csp: ' + cspEnabled, function() {
212212

213-
var originalSecurityPolicy;
214-
215-
216-
beforeEach(function() {
217-
originalSecurityPolicy = window.document.securityPolicy;
218-
window.document.securityPolicy = {isActive : cspEnabled};
219-
});
220-
221-
afterEach(function() {
222-
window.document.securityPolicy = originalSecurityPolicy;
223-
});
224-
225-
beforeEach(module(provideLog));
213+
beforeEach(module(function($provide) {
214+
$provide.decorator('$sniffer', function($delegate) {
215+
$delegate.csp = cspEnabled;
216+
return $delegate;
217+
});
218+
}, provideLog));
226219

227220
beforeEach(inject(function ($rootScope) {
228221
scope = $rootScope;

0 commit comments

Comments
 (0)