@@ -97,12 +97,19 @@ function $InterpolateProvider() {
9797
9898
9999 this . $get = [ '$parse' , '$exceptionHandler' , '$sce' , function ( $parse , $exceptionHandler , $sce ) {
100- var startSymbolLength = startSymbol . length ,
100+ var EVERY_CHAR = / ./ g,
101+ startSymbolLength = startSymbol . length ,
101102 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' ) ;
104107
105- function escape ( ch ) {
108+ function escapeForString ( ch ) {
109+ return '\\' + ch ;
110+ }
111+
112+ function escapeForRegex ( ch ) {
106113 return '\\\\\\' + ch ;
107114 }
108115
@@ -194,13 +201,6 @@ function $InterpolateProvider() {
194201 * replacing angle brackets (<, >) with &lt; and &gt; respectively, and replacing all
195202 * interpolation start/end markers with their escaped counterparts.**
196203 *
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- *
204204 * <example>
205205 * <file name="index.html">
206206 * <div ng-init="username='A user'">
@@ -232,10 +232,13 @@ function $InterpolateProvider() {
232232 * - `context`: evaluation context for all expressions embedded in the interpolated text
233233 */
234234 function $interpolate ( text , mustHaveExpression , trustedContext , allOrNothing ) {
235+ var hasEscapedMarkers = text . length &&
236+ ( text . indexOf ( escapedStartSymbol ) !== - 1 || text . indexOf ( escapedEndSymbol ) !== - 1 ) ;
237+
235238 // Provide a quick exit and simplified result function for text with no interpolation
236239 if ( ! text . length || text . indexOf ( startSymbol ) === - 1 ) {
237240 var constantInterp ;
238- if ( ! mustHaveExpression ) {
241+ if ( ! mustHaveExpression || hasEscapedMarkers ) {
239242 var unescapedText = unescapeText ( text ) ;
240243 constantInterp = valueFn ( unescapedText ) ;
241244 constantInterp . exp = text ;
@@ -257,8 +260,8 @@ function $InterpolateProvider() {
257260 expressionPositions = [ ] ;
258261
259262 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 ) ) {
262265 if ( index !== startIndex ) {
263266 concat . push ( unescapeText ( text . substring ( index , startIndex ) ) ) ;
264267 }
@@ -332,6 +335,12 @@ function $InterpolateProvider() {
332335 } ) ;
333336 }
334337 } ) ;
338+ } else if ( hasEscapedMarkers ) {
339+ return extend ( valueFn ( unescapeText ( text ) ) , {
340+ exp : text ,
341+ expressions : [ ] ,
342+ $$watchDelegate : constantWatchDelegate
343+ } ) ;
335344 }
336345
337346 function parseStringifyInterceptor ( value ) {
0 commit comments