@@ -71,6 +71,13 @@ describe('parser', function() {
71
71
expect ( tokens [ i ] . string ) . toEqual ( 'd"e' ) ;
72
72
} ) ;
73
73
74
+ it ( 'should tokenize identifiers with spaces after dots' , function ( ) {
75
+ var tokens = lex ( 'foo. bar' ) ;
76
+ expect ( tokens [ 0 ] . text ) . toEqual ( 'foo' ) ;
77
+ expect ( tokens [ 1 ] . text ) . toEqual ( '.' ) ;
78
+ expect ( tokens [ 2 ] . text ) . toEqual ( 'bar' ) ;
79
+ } ) ;
80
+
74
81
it ( 'should tokenize undefined' , function ( ) {
75
82
var tokens = lex ( "undefined" ) ;
76
83
var i = 0 ;
@@ -349,6 +356,28 @@ describe('parser', function() {
349
356
expect ( scope . $eval ( "x.y.z" , scope ) ) . not . toBeDefined ( ) ;
350
357
} ) ;
351
358
359
+ it ( 'should handle white-spaces around dots in paths' , function ( ) {
360
+ scope . a = { b : 4 } ;
361
+ expect ( scope . $eval ( "a . b" , scope ) ) . toEqual ( 4 ) ;
362
+ expect ( scope . $eval ( "a. b" , scope ) ) . toEqual ( 4 ) ;
363
+ expect ( scope . $eval ( "a .b" , scope ) ) . toEqual ( 4 ) ;
364
+ expect ( scope . $eval ( "a . \nb" , scope ) ) . toEqual ( 4 ) ;
365
+ } ) ;
366
+
367
+ it ( 'should throw syntax error exception for identifiers ending with a dot' , function ( ) {
368
+ scope . a = { b : 4 } ;
369
+
370
+ expect ( function ( ) {
371
+ scope . $eval ( "a." , scope ) ;
372
+ } ) . toThrowMinErr ( '$parse' , 'syntax' ,
373
+ "Token 'null' is an unexpected token at column 2 of the expression [a.] starting at [.]." ) ;
374
+
375
+ expect ( function ( ) {
376
+ scope . $eval ( "a ." , scope ) ;
377
+ } ) . toThrowMinErr ( '$parse' , 'syntax' ,
378
+ "Token 'null' is an unexpected token at column 3 of the expression [a .] starting at [.]." ) ;
379
+ } ) ;
380
+
352
381
it ( 'should resolve deeply nested paths (important for CSP mode)' , function ( ) {
353
382
scope . a = { b : { c : { d : { e : { f : { g : { h : { i : { j : { k : { l : { m : { n : 'nooo!' } } } } } } } } } } } } } ;
354
383
expect ( scope . $eval ( "a.b.c.d.e.f.g.h.i.j.k.l.m.n" , scope ) ) . toBe ( 'nooo!' ) ;
0 commit comments