Skip to content
Permalink
Browse files

fix($compile): properly denormalize templates when only one of the st…

…art/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
  • Loading branch information
gkalpak committed Jan 26, 2016
1 parent 543af65 commit 2d44a681eb912a81a8bc8e16a278c45dae91fa24
Showing with 49 additions and 1 deletion.
  1. +1 −1 src/ng/compile.js
  2. +48 −0 test/ng/compileSpec.js
@@ -1255,7 +1255,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {

var startSymbol = $interpolate.startSymbol(),
endSymbol = $interpolate.endSymbol(),
denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}')
denormalizeTemplate = (startSymbol == '{{' && endSymbol == '}}')
? identity
: function denormalizeTemplate(template) {
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
@@ -3118,6 +3118,54 @@ describe('$compile', function() {
});


it('should support custom start interpolation symbol, even when `endSymbol` doesn\'t change',
function() {
module(function($compileProvider, $interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$compileProvider.directive('myDirective', function() {
return {
template: '<span>{{ hello }}|{{ hello | uppercase }}</span>'
};
});
});

inject(function($compile, $rootScope) {
var tmpl = '<div>[[ hello | uppercase }}|<div my-directive></div></div>';
element = $compile(tmpl)($rootScope);

$rootScope.hello = 'ahoj';
$rootScope.$digest();

expect(element.text()).toBe('AHOJ|ahoj|AHOJ');
});
}
);


it('should support custom end interpolation symbol, even when `startSymbol` doesn\'t change',
function() {
module(function($compileProvider, $interpolateProvider) {
$interpolateProvider.endSymbol(']]');
$compileProvider.directive('myDirective', function() {
return {
template: '<span>{{ hello }}|{{ hello | uppercase }}</span>'
};
});
});

inject(function($compile, $rootScope) {
var tmpl = '<div>{{ hello | uppercase ]]|<div my-directive></div></div>';
element = $compile(tmpl)($rootScope);

$rootScope.hello = 'ahoj';
$rootScope.$digest();

expect(element.text()).toBe('AHOJ|ahoj|AHOJ');
});
}
);


it('should support custom start/end interpolation symbols in async directive template',
function() {
module(function($interpolateProvider, $compileProvider) {

0 comments on commit 2d44a68

Please sign in to comment.
You can’t perform that action at this time.