@@ -41,6 +41,8 @@ var $interpolateMinErr = minErr('$interpolate');
41
41
function $InterpolateProvider ( ) {
42
42
var startSymbol = '{{' ;
43
43
var endSymbol = '}}' ;
44
+ var quoteChars = '\'"' ;
45
+ var brackets = { "(" : ")" , "[" : "]" , "{" : "}" }
44
46
45
47
/**
46
48
* @ngdoc method
@@ -193,17 +195,42 @@ function $InterpolateProvider() {
193
195
textLength = text . length ,
194
196
exp ,
195
197
concat = [ ] ,
196
- expressionPositions = [ ] ;
198
+ expressionPositions = [ ] ,
199
+ quoteChar ,
200
+ bracketCounts = { } ,
201
+ ch ;
197
202
203
+ forEach ( brackets , function ( start , end ) {
204
+ bracketCounts [ start ] = 0 ;
205
+ bracketCounts [ end ] = 0 ;
206
+ } ) ;
198
207
while ( index < textLength ) {
199
208
if ( ( ( startIndex = text . indexOf ( startSymbol , index ) ) != - 1 ) &&
200
209
( ( endIndex = text . indexOf ( endSymbol , startIndex + startSymbolLength ) ) != - 1 ) ) {
201
210
if ( index !== startIndex ) {
202
211
concat . push ( unescapeText ( text . substring ( index , startIndex ) ) ) ;
203
212
}
213
+ index = startIndex + startSymbolLength ;
214
+ while ( index < endIndex || quoteChar !== undefined || ! bracketsMatch ( bracketCounts ) ) {
215
+ if ( index >= endIndex ) {
216
+ endIndex = text . indexOf ( endSymbol , endIndex + 1 ) ;
217
+ if ( endIndex === - 1 ) {
218
+ break ;
219
+ }
220
+ }
221
+ ch = text [ index ] ;
222
+ if ( quoteChar ) {
223
+ if ( quoteChar === ch ) quoteChar = undefined ;
224
+ else if ( ch === '\\' ) index ++ ;
225
+ } else {
226
+ if ( ch in bracketCounts ) bracketCounts [ ch ] ++ ;
227
+ else if ( quoteChars . indexOf ( ch ) != - 1 ) quoteChar = ch ;
228
+ }
229
+ index ++ ;
230
+ }
204
231
exp = text . substring ( startIndex + startSymbolLength , endIndex ) ;
205
- expressions . push ( exp ) ;
206
232
parseFns . push ( $parse ( exp , parseStringifyInterceptor ) ) ;
233
+ expressions . push ( exp ) ;
207
234
index = endIndex + endSymbolLength ;
208
235
expressionPositions . push ( concat . length ) ;
209
236
concat . push ( '' ) ;
@@ -312,6 +339,14 @@ function $InterpolateProvider() {
312
339
$exceptionHandler ( newErr ) ;
313
340
}
314
341
}
342
+
343
+ function bracketsMatch ( bracketCounts ) {
344
+ var match = true ;
345
+ forEach ( brackets , function ( start , end ) {
346
+ match &= bracketCounts [ start ] === bracketCounts [ end ] ;
347
+ } ) ;
348
+ return match ;
349
+ }
315
350
}
316
351
317
352
0 commit comments