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

fix($compile): properly denormalize templates when only one of the start/end symbols is different #13848

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,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);
Expand Down
48 changes: 48 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,54 @@ describe('$compile', function() {
});


it('should support custom start interpolation symbol, even when `endSymbol` doesn\'t change',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endSymbol is the default? (and below)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What @gkalpak means is that these test that the functionality works even if you change only one of startSymbol and endSymbol

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I just thought it was more explicit to state that the other symbol remains the default symbol. As is works for me though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to change it as @Narretz suggested upon merge, but forgot to amend the commit before pushing 😞

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) {
Expand Down