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

Commit 75d3784

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

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

Diff for: docs/content/error/$compile/ctxoverride.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@fullName Context Override
44
@description
55

6-
This error occurs when the security context for an attribute is defined multiple times under different security contexts.
6+
This error occurs when the security context for a property is defined multiple times under different security contexts.
77

88
For example:
99

Diff for: src/ng/compile.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -1599,11 +1599,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15991599
* @name $compileProvider#addPropertyContext
16001600
* @description
16011601
*
1602-
* Defines the security context for HTML properties bound by ng-prop-*
1602+
* Defines the security context for DOM properties bound by ng-prop-*
16031603
*
1604-
* @param {string} elementName the element name or '*' to match any element
1605-
* @param {string} propertyName the property name
1606-
* @param {string} ctx the context type
1604+
* @param {string} elementName The element name or '*' to match any element.
1605+
* @param {string} propertyName The DOM property name.
1606+
* @param {string} ctx The context in which this value is safe for use, e.g. $sce.URL,
1607+
* $sce.RESOURCE_URL, $sce.HTML, $sce.JS or $sce.CSS.
16071608
*/
16081609
this.addPropertyContext = function(elementName, propertyName, ctx) {
16091610
var key = (elementName.toLowerCase() + '|' + propertyName.toLowerCase());
@@ -1644,16 +1645,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16441645
'form|action',
16451646
'input|src',
16461647
'ins|cite',
1647-
'q|cite',
1648-
'script|src',
1649-
'video|poster'
1648+
'q|cite'
16501649
]);
16511650
registerContext(SCE_CONTEXTS.MEDIA_URL, [
16521651
'audio|src',
16531652
'img|src', 'img|srcset',
16541653
'source|src', 'source|srcset',
16551654
'track|src',
1656-
'video|src'
1655+
'video|src', 'video|poster'
16571656
]);
16581657
registerContext(SCE_CONTEXTS.RESOURCE_URL, [
16591658
'applet|code', 'applet|codebase',
@@ -1721,7 +1720,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
17211720
return value;
17221721
}
17231722
if (!isString(value)) {
1724-
throw $compileMinErr('srcset', 'Can\'t pass trusted values to `' + invokeType + '`: "{0}"', value.toString());
1723+
throw $compileMinErr('srcset', 'Can\'t pass trusted values to `{0}`: "{1}"', invokeType, value.toString());
17251724
}
17261725

17271726
// Such values are a bit too complex to handle automatically inside $sce.
@@ -2351,10 +2350,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23512350

23522351
// support ng-attr-*, ng-prop-* and ng-on-*
23532352
ngAttrName = directiveNormalize(name);
2354-
if (ngPrefixMatch = ngAttrName.match(NG_PREFIX_BINDING)) {
2355-
isNgAttr = ngPrefixMatch[1] === "Attr";
2356-
isNgProp = ngPrefixMatch[1] === "Prop";
2357-
isNgEvent = ngPrefixMatch[1] === "On";
2353+
if ((ngPrefixMatch = ngAttrName.match(NG_PREFIX_BINDING))) {
2354+
isNgAttr = ngPrefixMatch[1] === 'Attr';
2355+
isNgProp = ngPrefixMatch[1] === 'Prop';
2356+
isNgEvent = ngPrefixMatch[1] === 'On';
23582357

23592358
name = name.replace(PREFIX_REGEXP, '')
23602359
.substr(4 + ngPrefixMatch[1].length).replace(/_(.)/g, function(match, letter) {
@@ -3456,9 +3455,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34563455
}
34573456
}
34583457

3459-
function getTrustedPropContext(tag, propNormalizedName) {
3458+
function getTrustedPropContext(nodeName, propNormalizedName) {
34603459
var prop = propNormalizedName.toLowerCase();
3461-
return PROP_CONTEXTS[tag + "|" + prop] || PROP_CONTEXTS["*|" + prop];
3460+
return PROP_CONTEXTS[nodeName + "|" + prop] || PROP_CONTEXTS["*|" + prop];
34623461
}
34633462

34643463
function sanitizeSrcsetPropertyValue(value) {
@@ -3489,7 +3488,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34893488
return {
34903489
pre: function ngPropPreLinkFn(scope, $element) {
34913490
scope.$watch(fn, function propertyWatchActionFn(value) {
3492-
$element.prop(propName, value && sanitizer(value));
3491+
$element.prop(propName, sanitizer(value));
34933492
});
34943493
}
34953494
};
@@ -3504,8 +3503,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
35043503
}
35053504

35063505
function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) {
3507-
var tag = nodeName_(node);
3508-
var trustedContext = getTrustedAttrContext(tag, name);
3506+
var nodeName = nodeName_(node);
3507+
var trustedContext = getTrustedAttrContext(nodeName, name);
35093508
var mustHaveExpression = !isNgAttr;
35103509
var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr;
35113510

@@ -3514,7 +3513,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
35143513
// no interpolation found -> ignore
35153514
if (!interpolateFn) return;
35163515

3517-
if (name === 'multiple' && tag === 'select') {
3516+
if (name === 'multiple' && nodeName === 'select') {
35183517
throw $compileMinErr('selmulti',
35193518
'Binding to the \'multiple\' attribute is not supported. Element: {0}',
35203519
startingTag(node));

0 commit comments

Comments
 (0)