@@ -97,12 +97,19 @@ function $InterpolateProvider() {
97
97
98
98
99
99
this . $get = [ '$parse' , '$exceptionHandler' , '$sce' , function ( $parse , $exceptionHandler , $sce ) {
100
- var startSymbolLength = startSymbol . length ,
100
+ var EVERY_CHAR = / ./ g,
101
+ startSymbolLength = startSymbol . length ,
101
102
endSymbolLength = endSymbol . length ,
102
- escapedStartRegexp = new RegExp ( startSymbol . replace ( / ./ g, escape ) , 'g' ) ,
103
- escapedEndRegexp = new RegExp ( endSymbol . replace ( / ./ g, escape ) , 'g' ) ;
103
+ escapedStartSymbol = startSymbol . replace ( EVERY_CHAR , escapeForString ) ,
104
+ escapedEndSymbol = endSymbol . replace ( EVERY_CHAR , escapeForString ) ,
105
+ escapedStartRegexp = new RegExp ( startSymbol . replace ( EVERY_CHAR , escapeForRegex ) , 'g' ) ,
106
+ escapedEndRegexp = new RegExp ( endSymbol . replace ( EVERY_CHAR , escapeForRegex ) , 'g' ) ;
104
107
105
- function escape ( ch ) {
108
+ function escapeForString ( ch ) {
109
+ return '\\' + ch ;
110
+ }
111
+
112
+ function escapeForRegex ( ch ) {
106
113
return '\\\\\\' + ch ;
107
114
}
108
115
@@ -194,13 +201,6 @@ function $InterpolateProvider() {
194
201
* replacing angle brackets (<, >) with &lt; and &gt; respectively, and replacing all
195
202
* interpolation start/end markers with their escaped counterparts.**
196
203
*
197
- * Escaped interpolation markers are only replaced with the actual interpolation markers in rendered
198
- * output when the $interpolate service processes the text. So, for HTML elements interpolated
199
- * by {@link ng.$compile $compile}, or otherwise interpolated with the `mustHaveExpression` parameter
200
- * set to `true`, the interpolated text must contain an unescaped interpolation expression. As such,
201
- * this is typically useful only when user-data is used in rendering a template from the server, or
202
- * when otherwise untrusted data is used by a directive.
203
- *
204
204
* <example>
205
205
* <file name="index.html">
206
206
* <div ng-init="username='A user'">
@@ -232,10 +232,13 @@ function $InterpolateProvider() {
232
232
* - `context`: evaluation context for all expressions embedded in the interpolated text
233
233
*/
234
234
function $interpolate ( text , mustHaveExpression , trustedContext , allOrNothing ) {
235
+ var hasEscapedMarkers = text . length &&
236
+ ( text . indexOf ( escapedStartSymbol ) !== - 1 || text . indexOf ( escapedEndSymbol ) !== - 1 ) ;
237
+
235
238
// Provide a quick exit and simplified result function for text with no interpolation
236
239
if ( ! text . length || text . indexOf ( startSymbol ) === - 1 ) {
237
240
var constantInterp ;
238
- if ( ! mustHaveExpression ) {
241
+ if ( ! mustHaveExpression || hasEscapedMarkers ) {
239
242
var unescapedText = unescapeText ( text ) ;
240
243
constantInterp = valueFn ( unescapedText ) ;
241
244
constantInterp . exp = text ;
@@ -257,8 +260,8 @@ function $InterpolateProvider() {
257
260
expressionPositions = [ ] ;
258
261
259
262
while ( index < textLength ) {
260
- if ( ( ( startIndex = text . indexOf ( startSymbol , index ) ) != - 1 ) &&
261
- ( ( endIndex = text . indexOf ( endSymbol , startIndex + startSymbolLength ) ) != - 1 ) ) {
263
+ if ( ( ( startIndex = text . indexOf ( startSymbol , index ) ) !== - 1 ) &&
264
+ ( ( endIndex = text . indexOf ( endSymbol , startIndex + startSymbolLength ) ) != = - 1 ) ) {
262
265
if ( index !== startIndex ) {
263
266
concat . push ( unescapeText ( text . substring ( index , startIndex ) ) ) ;
264
267
}
@@ -332,6 +335,12 @@ function $InterpolateProvider() {
332
335
} ) ;
333
336
}
334
337
} ) ;
338
+ } else if ( hasEscapedMarkers ) {
339
+ return extend ( valueFn ( unescapeText ( text ) ) , {
340
+ exp : text ,
341
+ expressions : [ ] ,
342
+ $$watchDelegate : constantWatchDelegate
343
+ } ) ;
335
344
}
336
345
337
346
function parseStringifyInterceptor ( value ) {
0 commit comments