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

Commit e1ce56e

Browse files
committed
fixup! feat($compile): add support for arbitrary property and event bindings
1 parent bd63689 commit e1ce56e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/ng/compile.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34613461
return PROP_CONTEXTS[tag + "|" + prop] || PROP_CONTEXTS["*|" + prop];
34623462
}
34633463

3464+
function sanitizeSrcsetPropertyValue(value) {
3465+
return sanitizeSrcset($sce.valueOf(value), 'ng-prop-srcset');
3466+
}
34643467
function addPropertyDirective(node, directives, attrName, propName) {
34653468
if (EVENT_HANDLER_ATTR_REGEXP.test(propName)) {
34663469
throw $compileMinErr('nodomevents',
@@ -3471,23 +3474,22 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34713474
var nodeName = nodeName_(node);
34723475
var trustedContext = getTrustedPropContext(nodeName, propName);
34733476

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+
34743485
directives.push({
34753486
priority: 100,
34763487
compile: function ngPropCompileFn(_, attr) {
34773488
var fn = $parse(attr[attrName]);
34783489
return {
34793490
pre: function ngPropPreLinkFn(scope, $element) {
34803491
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));
34913493
});
34923494
}
34933495
};

0 commit comments

Comments
 (0)