Skip to content

Commit 8348365

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 angular#13848
1 parent 16bcdcb commit 8348365

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
@@ -1559,7 +1559,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15591559

15601560
var startSymbol = $interpolate.startSymbol(),
15611561
endSymbol = $interpolate.endSymbol(),
1562-
denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}')
1562+
denormalizeTemplate = (startSymbol == '{{' && endSymbol == '}}')
15631563
? identity
15641564
: function denormalizeTemplate(template) {
15651565
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
@@ -3137,6 +3137,54 @@ describe('$compile', function() {
31373137
});
31383138

31393139

3140+
it('should support custom start interpolation symbol, even when `endSymbol` doesn\'t change',
3141+
function() {
3142+
module(function($compileProvider, $interpolateProvider) {
3143+
$interpolateProvider.startSymbol('[[');
3144+
$compileProvider.directive('myDirective', function() {
3145+
return {
3146+
template: '<span>{{ hello }}|{{ hello | uppercase }}</span>'
3147+
};
3148+
});
3149+
});
3150+
3151+
inject(function($compile, $rootScope) {
3152+
var tmpl = '<div>[[ hello | uppercase }}|<div my-directive></div></div>';
3153+
element = $compile(tmpl)($rootScope);
3154+
3155+
$rootScope.hello = 'ahoj';
3156+
$rootScope.$digest();
3157+
3158+
expect(element.text()).toBe('AHOJ|ahoj|AHOJ');
3159+
});
3160+
}
3161+
);
3162+
3163+
3164+
it('should support custom end interpolation symbol, even when `startSymbol` doesn\'t change',
3165+
function() {
3166+
module(function($compileProvider, $interpolateProvider) {
3167+
$interpolateProvider.endSymbol(']]');
3168+
$compileProvider.directive('myDirective', function() {
3169+
return {
3170+
template: '<span>{{ hello }}|{{ hello | uppercase }}</span>'
3171+
};
3172+
});
3173+
});
3174+
3175+
inject(function($compile, $rootScope) {
3176+
var tmpl = '<div>{{ hello | uppercase ]]|<div my-directive></div></div>';
3177+
element = $compile(tmpl)($rootScope);
3178+
3179+
$rootScope.hello = 'ahoj';
3180+
$rootScope.$digest();
3181+
3182+
expect(element.text()).toBe('AHOJ|ahoj|AHOJ');
3183+
});
3184+
}
3185+
);
3186+
3187+
31403188
it('should support custom start/end interpolation symbols in async directive template',
31413189
function() {
31423190
module(function($interpolateProvider, $compileProvider) {

0 commit comments

Comments
 (0)