@@ -236,6 +236,26 @@ describe('ngProp*', function() {
236
236
$rootScope . $digest ( ) ;
237
237
expect ( element . prop ( 'src' ) ) . toEqual ( 'untrusted:foo()' ) ;
238
238
} ) ) ;
239
+
240
+ it ( 'should sanitize non-whitelisted values' , inject ( function ( $rootScope , $compile , $sce ) {
241
+ // As a MEDIA_URL URL
242
+ var element = $compile ( '<' + tag + ' ng-prop-src="testUrl"></' + tag + '>' ) ( $rootScope ) ;
243
+ // Some browsers complain if you try to write `javascript:` into an `img[src]`
244
+ // So for the test use something different
245
+ $rootScope . testUrl = 'untrusted:foo()' ;
246
+ $rootScope . $digest ( ) ;
247
+ expect ( element . prop ( 'src' ) ) . toEqual ( 'unsafe:untrusted:foo()' ) ;
248
+ } ) ) ;
249
+
250
+ it ( 'should sanitize wrongly typed values' , inject ( function ( $rootScope , $compile , $sce ) {
251
+ // As a MEDIA_URL URL
252
+ var element = $compile ( '<' + tag + ' ng-prop-src="testUrl"></' + tag + '>' ) ( $rootScope ) ;
253
+ // Some browsers complain if you try to write `javascript:` into an `img[src]`
254
+ // So for the test use something different
255
+ $rootScope . testUrl = $sce . trustAsCss ( 'untrusted:foo()' ) ;
256
+ $rootScope . $digest ( ) ;
257
+ expect ( element . prop ( 'src' ) ) . toEqual ( 'unsafe:untrusted:foo()' ) ;
258
+ } ) ) ;
239
259
} ) ;
240
260
}
241
261
} ) ;
@@ -272,6 +292,20 @@ describe('ngProp*', function() {
272
292
$rootScope . $digest ( ) ;
273
293
expect ( element . find ( tag ) . prop ( 'src' ) ) . toEqual ( 'javascript:foo()' ) ;
274
294
} ) ) ;
295
+
296
+ it ( 'should sanitize non-whitelisted values' , inject ( function ( $rootScope , $compile , $sce ) {
297
+ var element = $compile ( '<video><' + tag + ' ng-prop-src="testUrl"></' + tag + '></video>' ) ( $rootScope ) ;
298
+ $rootScope . testUrl = 'untrusted:foo()' ;
299
+ $rootScope . $digest ( ) ;
300
+ expect ( element . find ( tag ) . prop ( 'src' ) ) . toEqual ( 'unsafe:untrusted:foo()' ) ;
301
+ } ) ) ;
302
+
303
+ it ( 'should sanitize wrongly typed values' , inject ( function ( $rootScope , $compile , $sce ) {
304
+ var element = $compile ( '<video><' + tag + ' ng-prop-src="testUrl"></' + tag + '></video>' ) ( $rootScope ) ;
305
+ $rootScope . testUrl = $sce . trustAsCss ( 'untrusted:foo()' ) ;
306
+ $rootScope . $digest ( ) ;
307
+ expect ( element . find ( tag ) . prop ( 'src' ) ) . toEqual ( 'unsafe:untrusted:foo()' ) ;
308
+ } ) ) ;
275
309
} ) ;
276
310
} ) ;
277
311
}
0 commit comments