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

Commit fae5066

Browse files
author
Jason Bedard
committed
fixup! feat($compile): add support for arbitrary property and event bindings
1 parent 13bab70 commit fae5066

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

Diff for: test/ng/compileSpec.js

+64
Original file line numberDiff line numberDiff line change
@@ -12179,6 +12179,70 @@ describe('$compile', function() {
1217912179
$compileProvider.addPropertySecurityContext('div', 'title', 'mediaUrl');
1218012180
});
1218112181
});
12182+
12183+
it('should enforce the specified sce type for properties added for specific elements', function() {
12184+
module(function($compileProvider) {
12185+
$compileProvider.addPropertySecurityContext('div', 'foo', 'mediaUrl');
12186+
});
12187+
inject(function($compile, $rootScope, $sce) {
12188+
var element = $compile('<div ng-prop-foo="bar"></div>')($rootScope);
12189+
12190+
$rootScope.bar = 'untrusted:test1';
12191+
$rootScope.$apply();
12192+
expect(element.prop('foo')).toBe('unsafe:untrusted:test1');
12193+
12194+
$rootScope.bar = $sce.trustAsCss('untrusted:test2');
12195+
$rootScope.$apply();
12196+
expect(element.prop('foo')).toBe('unsafe:untrusted:test2');
12197+
12198+
$rootScope.bar = $sce.trustAsMediaUrl('untrusted:test3');
12199+
$rootScope.$apply();
12200+
expect(element.prop('foo')).toBe('untrusted:test3');
12201+
});
12202+
});
12203+
12204+
it('should enforce the specified sce type for properties added for all elements (*)', function() {
12205+
module(function($compileProvider) {
12206+
$compileProvider.addPropertySecurityContext('*', 'foo', 'mediaUrl');
12207+
});
12208+
inject(function($compile, $rootScope, $sce) {
12209+
var element = $compile('<div ng-prop-foo="bar"></div>')($rootScope);
12210+
12211+
$rootScope.bar = 'untrusted:test1';
12212+
$rootScope.$apply();
12213+
expect(element.prop('foo')).toBe('unsafe:untrusted:test1');
12214+
12215+
$rootScope.bar = $sce.trustAsCss('untrusted:test2');
12216+
$rootScope.$apply();
12217+
expect(element.prop('foo')).toBe('unsafe:untrusted:test2');
12218+
12219+
$rootScope.bar = $sce.trustAsMediaUrl('untrusted:test3');
12220+
$rootScope.$apply();
12221+
expect(element.prop('foo')).toBe('untrusted:test3');
12222+
});
12223+
});
12224+
12225+
it('should enforce the specific sce type when both an element specific and generic exist', function() {
12226+
module(function($compileProvider) {
12227+
$compileProvider.addPropertySecurityContext('*', 'foo', 'css');
12228+
$compileProvider.addPropertySecurityContext('div', 'foo', 'mediaUrl');
12229+
});
12230+
inject(function($compile, $rootScope, $sce) {
12231+
var element = $compile('<div ng-prop-foo="bar"></div>')($rootScope);
12232+
12233+
$rootScope.bar = 'untrusted:test1';
12234+
$rootScope.$apply();
12235+
expect(element.prop('foo')).toBe('unsafe:untrusted:test1');
12236+
12237+
$rootScope.bar = $sce.trustAsCss('untrusted:test2');
12238+
$rootScope.$apply();
12239+
expect(element.prop('foo')).toBe('unsafe:untrusted:test2');
12240+
12241+
$rootScope.bar = $sce.trustAsMediaUrl('untrusted:test3');
12242+
$rootScope.$apply();
12243+
expect(element.prop('foo')).toBe('untrusted:test3');
12244+
});
12245+
});
1218212246
});
1218312247

1218412248

0 commit comments

Comments
 (0)