@@ -3461,6 +3461,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3461
3461
return PROP_CONTEXTS [ tag + "|" + prop ] || PROP_CONTEXTS [ "*|" + prop ] ;
3462
3462
}
3463
3463
3464
+ function sanitizeSrcsetPropertyValue ( value ) {
3465
+ return sanitizeSrcset ( $sce . valueOf ( value ) , 'ng-prop-srcset' ) ;
3466
+ }
3464
3467
function addPropertyDirective ( node , directives , attrName , propName ) {
3465
3468
if ( EVENT_HANDLER_ATTR_REGEXP . test ( propName ) ) {
3466
3469
throw $compileMinErr ( 'nodomevents' ,
@@ -3471,23 +3474,22 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3471
3474
var nodeName = nodeName_ ( node ) ;
3472
3475
var trustedContext = getTrustedPropContext ( nodeName , propName ) ;
3473
3476
3477
+ var sanitizer = identity ;
3478
+ // Sanitize img[srcset] + source[srcset] values.
3479
+ if ( ( nodeName === 'img' || nodeName === 'source' ) && propName === 'srcset' ) {
3480
+ sanitizer = sanitizeSrcsetPropertyValue ;
3481
+ } else if ( trustedContext ) {
3482
+ sanitizer = $sce . getTrusted . bind ( $sce , trustedContext ) ;
3483
+ }
3484
+
3474
3485
directives . push ( {
3475
3486
priority : 100 ,
3476
3487
compile : function ngPropCompileFn ( _ , attr ) {
3477
3488
var fn = $parse ( attr [ attrName ] ) ;
3478
3489
return {
3479
3490
pre : function ngPropPreLinkFn ( scope , $element ) {
3480
3491
scope . $watch ( fn , function propertyWatchActionFn ( value ) {
3481
- if ( value ) {
3482
- // Sanitize img[srcset] + source[srcset] values.
3483
- if ( ( nodeName === 'img' || nodeName === 'source' ) && propName === 'srcset' ) {
3484
- value = sanitizeSrcset ( $sce . valueOf ( value ) , 'ng-prop-srcset' ) ;
3485
- } else if ( trustedContext ) {
3486
- value = $sce . getTrusted ( trustedContext , value ) ;
3487
- }
3488
- }
3489
-
3490
- $element . prop ( propName , value ) ;
3492
+ $element . prop ( propName , value && sanitizer ( value ) ) ;
3491
3493
} ) ;
3492
3494
}
3493
3495
} ;
0 commit comments