@@ -12179,6 +12179,70 @@ describe('$compile', function() {
12179
12179
$compileProvider . addPropertySecurityContext ( 'div' , 'title' , 'mediaUrl' ) ;
12180
12180
} ) ;
12181
12181
} ) ;
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
+ } ) ;
12182
12246
} ) ;
12183
12247
12184
12248
0 commit comments