This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +23
-4
lines changed
2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -201,9 +201,20 @@ function $InterpolateProvider() {
201
201
if ( index !== startIndex ) {
202
202
concat . push ( unescapeText ( text . substring ( index , startIndex ) ) ) ;
203
203
}
204
- exp = text . substring ( startIndex + startSymbolLength , endIndex ) ;
205
- expressions . push ( exp ) ;
206
- parseFns . push ( $parse ( exp , parseStringifyInterceptor ) ) ;
204
+ do {
205
+ try {
206
+ exp = text . substring ( startIndex + startSymbolLength , endIndex ) ;
207
+ parseFns . push ( $parse ( exp , parseStringifyInterceptor ) ) ;
208
+ expressions . push ( exp ) ;
209
+ } catch ( e ) {
210
+ endIndex = text . indexOf ( endSymbol , endIndex + 1 ) ;
211
+ if ( endIndex === - 1 ) {
212
+ throw e ;
213
+ } else {
214
+ exp = undefined ;
215
+ }
216
+ }
217
+ } while ( isUndefined ( exp ) ) ;
207
218
index = endIndex + endSymbolLength ;
208
219
expressionPositions . push ( concat . length ) ;
209
220
concat . push ( '' ) ;
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ describe('$interpolate', function() {
105
105
expect ( function ( ) {
106
106
$interpolate ( '{{\\{\\{foo\\}\\}}}' ) ( obj ) ;
107
107
} ) . toThrowMinErr ( '$parse' , 'lexerr' ,
108
- 'Lexer Error: Unexpected next character at columns 0-0 [\\] in expression [\\{\\{foo\\}\\]' ) ;
108
+ 'Lexer Error: Unexpected next character at columns 0-0 [\\] in expression [\\{\\{foo\\}\\} ]' ) ;
109
109
} ) ) ;
110
110
111
111
@@ -116,6 +116,14 @@ describe('$interpolate', function() {
116
116
it ( 'should evaluate expressions between escaped start/end symbols' , inject ( function ( $interpolate ) {
117
117
expect ( $interpolate ( '\\{\\{Hello, {{bar}}!\\}\\}' ) ( obj ) ) . toBe ( '{{Hello, World!}}' ) ;
118
118
} ) ) ;
119
+
120
+ it ( 'should pick the first end symbol location that forms a valid expression' , inject ( function ( $interpolate ) {
121
+ expect ( $interpolate ( '{{{}}}' ) ( obj ) ) . toBe ( '{}' ) ;
122
+ expect ( $interpolate ( '{{"{{ }}"}}' ) ( obj ) ) . toBe ( '{{ }}' ) ;
123
+ expect ( $interpolate ( '{{{foo: "bar"}}}' ) ( obj ) ) . toBe ( '{"foo":"bar"}' ) ;
124
+ expect ( $interpolate ( '{{{foo: {"bar": "baz"}}}}' ) ( obj ) ) . toBe ( '{"foo":{"bar":"baz"}}' ) ;
125
+ expect ( $interpolate ( '{{[{foo: {"bar": "baz"}}]}}' ) ( obj ) ) . toBe ( '[{"foo":{"bar":"baz"}}]' ) ;
126
+ } ) ) ;
119
127
} ) ;
120
128
121
129
You can’t perform that action at this time.
0 commit comments