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

Commit 2d44a68

Browse files
committed
fix($compile): properly denormalize templates when only one of the start/end symbols is different
Previously, if either of the start/end interpolation symbols remained unchanged (i.e. `{{` or `}}`), then directive templates would not be denormalized properly. Changing only one of the start/end symbols (but not both) is an uncommon but legitimate usecase. Closes #13848
1 parent 543af65 commit 2d44a68

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/ng/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
12551255

12561256
var startSymbol = $interpolate.startSymbol(),
12571257
endSymbol = $interpolate.endSymbol(),
1258-
denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}')
1258+
denormalizeTemplate = (startSymbol == '{{' && endSymbol == '}}')
12591259
? identity
12601260
: function denormalizeTemplate(template) {
12611261
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);

test/ng/compileSpec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,54 @@ describe('$compile', function() {
31183118
});
31193119

31203120

3121+
it('should support custom start interpolation symbol, even when `endSymbol` doesn\'t change',
3122+
function() {
3123+
module(function($compileProvider, $interpolateProvider) {
3124+
$interpolateProvider.startSymbol('[[');
3125+
$compileProvider.directive('myDirective', function() {
3126+
return {
3127+
template: '<span>{{ hello }}|{{ hello | uppercase }}</span>'
3128+
};
3129+
});
3130+
});
3131+
3132+
inject(function($compile, $rootScope) {
3133+
var tmpl = '<div>[[ hello | uppercase }}|<div my-directive></div></div>';
3134+
element = $compile(tmpl)($rootScope);
3135+
3136+
$rootScope.hello = 'ahoj';
3137+
$rootScope.$digest();
3138+
3139+
expect(element.text()).toBe('AHOJ|ahoj|AHOJ');
3140+
});
3141+
}
3142+
);
3143+
3144+
3145+
it('should support custom end interpolation symbol, even when `startSymbol` doesn\'t change',
3146+
function() {
3147+
module(function($compileProvider, $interpolateProvider) {
3148+
$interpolateProvider.endSymbol(']]');
3149+
$compileProvider.directive('myDirective', function() {
3150+
return {
3151+
template: '<span>{{ hello }}|{{ hello | uppercase }}</span>'
3152+
};
3153+
});
3154+
});
3155+
3156+
inject(function($compile, $rootScope) {
3157+
var tmpl = '<div>{{ hello | uppercase ]]|<div my-directive></div></div>';
3158+
element = $compile(tmpl)($rootScope);
3159+
3160+
$rootScope.hello = 'ahoj';
3161+
$rootScope.$digest();
3162+
3163+
expect(element.text()).toBe('AHOJ|ahoj|AHOJ');
3164+
});
3165+
}
3166+
);
3167+
3168+
31213169
it('should support custom start/end interpolation symbols in async directive template',
31223170
function() {
31233171
module(function($interpolateProvider, $compileProvider) {

0 commit comments

Comments
 (0)