File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed
src/core/change_detection/parser
test/core/change_detection/parser Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -395,6 +395,18 @@ function isIdentifierStart(code: number): boolean {
395395 return ( $a <= code && code <= $z ) || ( $A <= code && code <= $Z ) || ( code == $_ ) || ( code == $$ ) ;
396396}
397397
398+ export function isIdentifier ( input : string ) : boolean {
399+ if ( input . length == 0 ) return false ;
400+ var scanner = new _Scanner ( input ) ;
401+ if ( ! isIdentifierStart ( scanner . peek ) ) return false ;
402+ scanner . advance ( ) ;
403+ while ( scanner . peek !== $EOF ) {
404+ if ( ! isIdentifierPart ( scanner . peek ) ) return false ;
405+ scanner . advance ( ) ;
406+ }
407+ return true ;
408+ }
409+
398410function isIdentifierPart ( code : number ) : boolean {
399411 return ( $a <= code && code <= $z ) || ( $A <= code && code <= $Z ) || ( $0 <= code && code <= $9 ) ||
400412 ( code == $_ ) || ( code == $$ ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import {ListWrapper} from 'angular2/src/facade/collection';
55import {
66 Lexer ,
77 EOF ,
8+ isIdentifier ,
89 Token ,
910 $PERIOD ,
1011 $COLON ,
@@ -105,15 +106,10 @@ export class Parser {
105106 if ( isBlank ( input ) ) return null ;
106107 var prefixSeparatorIndex = input . indexOf ( ':' ) ;
107108 if ( prefixSeparatorIndex == - 1 ) return null ;
108- var prefix = input . substring ( 0 , prefixSeparatorIndex ) ;
109+ var prefix = input . substring ( 0 , prefixSeparatorIndex ) . trim ( ) ;
110+ if ( ! isIdentifier ( prefix ) ) return null ;
109111 var uninterpretedExpression = input . substring ( prefixSeparatorIndex + 1 ) ;
110-
111- // while we do not interpret the expression, we do interpret the prefix
112- var prefixTokens = this . _lexer . tokenize ( prefix ) ;
113-
114- // quote prefix must be a single legal identifier
115- if ( prefixTokens . length != 1 || ! prefixTokens [ 0 ] . isIdentifier ( ) ) return null ;
116- return new Quote ( prefixTokens [ 0 ] . strValue , uninterpretedExpression , location ) ;
112+ return new Quote ( prefix , uninterpretedExpression , location ) ;
117113 }
118114
119115 parseTemplateBindings ( input : string , location : any ) : TemplateBinding [ ] {
Original file line number Diff line number Diff line change @@ -233,6 +233,9 @@ export function main() {
233233
234234 it ( 'should parse quoted expressions' , ( ) => { checkBinding ( 'a:b' , 'a:b' ) ; } ) ;
235235
236+ it ( 'should not crash when prefix part is not tokenizable' ,
237+ ( ) => { checkBinding ( '"a:b"' , '"a:b"' ) ; } ) ;
238+
236239 it ( 'should ignore whitespace around quote prefix' , ( ) => { checkBinding ( ' a :b' , 'a:b' ) ; } ) ;
237240
238241 it ( 'should refuse prefixes that are not single identifiers' , ( ) => {
You can’t perform that action at this time.
0 commit comments