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

Commit 1ba411e

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

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

docs/content/error/$compile/ctxoverride.ngdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ This error occurs when the security context for a property is defined multiple t
88
For example:
99

1010
```
11-
$compileProvider.addPropertyContext("my-element", "src", "mediaUrl");
12-
$compileProvider.addPropertyContext("my-element", "src", "resourceUrl"); //throws
11+
$compileProvider.addPropertySecurityContext("my-element", "src", "mediaUrl");
12+
$compileProvider.addPropertySecurityContext("my-element", "src", "resourceUrl"); //throws
1313
```

src/ng/compile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15961596

15971597
/**
15981598
* @ngdoc method
1599-
* @name $compileProvider#addPropertyContext
1599+
* @name $compileProvider#addPropertySecurityContext
16001600
* @description
16011601
*
16021602
* Defines the security context for DOM properties bound by ng-prop-*
@@ -1606,7 +1606,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16061606
* @param {string} ctx The context in which this value is safe for use, e.g. $sce.URL,
16071607
* $sce.RESOURCE_URL, $sce.HTML, $sce.JS or $sce.CSS.
16081608
*/
1609-
this.addPropertyContext = function(elementName, propertyName, ctx) {
1609+
this.addPropertySecurityContext = function(elementName, propertyName, ctx) {
16101610
var key = (elementName.toLowerCase() + '|' + propertyName.toLowerCase());
16111611

16121612
if (key in PROP_CONTEXTS && PROP_CONTEXTS[key] !== ctx) {
@@ -1624,7 +1624,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16241624
* - STYLE => CSS
16251625
* - various URL => MEDIA_URL
16261626
*/
1627-
(function setupPropertyContexts() {
1627+
(function registerNativePropertyContexts() {
16281628
function registerContext(ctx, values) {
16291629
forEach(values, function(v) { PROP_CONTEXTS[v.toLowerCase()] = ctx; });
16301630
}

test/ng/compileSpec.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -12642,43 +12642,43 @@ describe('$compile', function() {
1264212642
});
1264312643
});
1264412644

12645-
describe('addPropertyContext', function() {
12645+
describe('addPropertySecurityContext', function() {
1264612646
function testProvider(provider) {
1264712647
module(provider);
1264812648
inject(function($compile) { /* done! */});
1264912649
}
1265012650

1265112651
it('should allow adding new properties', function() {
1265212652
testProvider(function($compileProvider) {
12653-
$compileProvider.addPropertyContext('div', 'title', 'mediaUrl');
12654-
$compileProvider.addPropertyContext('*', 'my-prop', 'resourceUrl');
12653+
$compileProvider.addPropertySecurityContext('div', 'title', 'mediaUrl');
12654+
$compileProvider.addPropertySecurityContext('*', 'my-prop', 'resourceUrl');
1265512655
});
1265612656
});
1265712657

1265812658
it('should allow different sce types of a property on different element types', function() {
1265912659
testProvider(function($compileProvider) {
12660-
$compileProvider.addPropertyContext('div', 'title', 'mediaUrl');
12661-
$compileProvider.addPropertyContext('span', 'title', 'css');
12662-
$compileProvider.addPropertyContext('*', 'title', 'resourceUrl');
12663-
$compileProvider.addPropertyContext('article', 'title', 'html');
12660+
$compileProvider.addPropertySecurityContext('div', 'title', 'mediaUrl');
12661+
$compileProvider.addPropertySecurityContext('span', 'title', 'css');
12662+
$compileProvider.addPropertySecurityContext('*', 'title', 'resourceUrl');
12663+
$compileProvider.addPropertySecurityContext('article', 'title', 'html');
1266412664
});
1266512665
});
1266612666

1266712667
it('should throw \'ctxoverride\' when changing an existing context', function() {
1266812668
testProvider(function($compileProvider) {
12669-
$compileProvider.addPropertyContext('div', 'title', 'mediaUrl');
12669+
$compileProvider.addPropertySecurityContext('div', 'title', 'mediaUrl');
1267012670

1267112671
expect(function() {
12672-
$compileProvider.addPropertyContext('div', 'title', 'resourceUrl');
12672+
$compileProvider.addPropertySecurityContext('div', 'title', 'resourceUrl');
1267312673
})
1267412674
.toThrowMinErr('$compile', 'ctxoverride', 'Property context \'div.title\' already set to \'mediaUrl\', cannot override to \'resourceUrl\'.');
1267512675
});
1267612676
});
1267712677

1267812678
it('should setting the same property/element to the same value', function() {
1267912679
testProvider(function($compileProvider) {
12680-
$compileProvider.addPropertyContext('div', 'title', 'mediaUrl');
12681-
$compileProvider.addPropertyContext('div', 'title', 'mediaUrl');
12680+
$compileProvider.addPropertySecurityContext('div', 'title', 'mediaUrl');
12681+
$compileProvider.addPropertySecurityContext('div', 'title', 'mediaUrl');
1268212682
});
1268312683
});
1268412684
});

0 commit comments

Comments
 (0)