Skip to content

Commit cd21602

Browse files
committed
fix(ngBindHtml): throw error if interpolation is used in expression
Closes angular#8824
1 parent 5f3f25a commit cd21602

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/ng/directive/ngBind.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ var ngBindHtmlDirective = ['$sce', '$parse', '$compile', function($sce, $parse,
186186
return {
187187
restrict: 'A',
188188
compile: function ngBindHtmlCompile(tElement, tAttrs) {
189+
var ngBindHtmlGetter = $parse(tAttrs.ngBindHtml);
190+
var ngBindHtmlWatch = $parse(tAttrs.ngBindHtml, function getStringValue(value) {
191+
return (value || '').toString();
192+
});
189193
$compile.$$addBindingClass(tElement);
190194

191195
return function ngBindHtmlLink(scope, element, attr) {
192196
$compile.$$addBindingInfo(element, attr.ngBindHtml);
193-
var ngBindHtmlGetter = $parse(attr.ngBindHtml);
194-
var ngBindHtmlWatch = $parse(attr.ngBindHtml, function getStringValue(value) {
195-
return (value || '').toString();
196-
});
197197

198198
scope.$watch(ngBindHtmlWatch, function ngBindHtmlWatchAction() {
199199
// we re-evaluate the expr because we want a TrustedValueHolderType

test/ng/directive/ngBindSpec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ describe('ngBind*', function() {
122122

123123
describe('ngBindHtml', function() {
124124

125+
it('should complain about accidental use of interpolation', inject(function($compile) {
126+
expect(function() {
127+
$compile('<div ng-bind-html="{{myHtml}}"></div>');
128+
}).toThrowMinErr('$parse', 'syntax', "Syntax Error: Token 'myHtml' is unexpected, " +
129+
"expecting [:] at column 3 of the expression [{{myHtml}}] starting at [myHtml}}].");
130+
}));
131+
132+
125133
describe('SCE disabled', function() {
126134
beforeEach(function() {
127135
module(function($sceProvider) { $sceProvider.enabled(false); });

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy