From fcb3617011de31554ee1654c90a7d68bfaecd434 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 9 Aug 2014 22:55:21 +0200 Subject: [PATCH] fix($parse): allow spaces around dots for identifiers Fixes #4613 Closes #8550 --- src/ng/parse.js | 8 ++++---- test/ng/parseSpec.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 2730e6cc3f5b..e270288453da 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -263,15 +263,15 @@ Lexer.prototype = { var ident = ''; var start = this.index; - var lastDot, peekIndex, methodName, ch; + var lastDot, expectIdent, peekIndex, methodName, ch; while (this.index < this.text.length) { ch = this.text.charAt(this.index); if (ch === '.' || this.isIdent(ch) || this.isNumber(ch)) { - if (ch === '.') lastDot = this.index; + if (expectIdent = ch === '.') lastDot = this.index; ident += ch; - } else { - break; + } else if (!(this.isWhitespace(ch) && expectIdent)) { + break; } this.index++; } diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 27994bd0881c..50ef00a0d1f9 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -71,6 +71,10 @@ describe('parser', function() { expect(tokens[i].string).toEqual('d"e'); }); + it('should tokenize identifiers with spaces after dots', function () { + expect(lex('foo. bar')[0].text).toEqual('foo.bar'); + }); + it('should tokenize undefined', function() { var tokens = lex("undefined"); var i = 0; @@ -349,6 +353,14 @@ describe('parser', function() { expect(scope.$eval("x.y.z", scope)).not.toBeDefined(); }); + it('should handle white-spaces around dots in paths', function () { + scope.a = {b: 4}; + expect(scope.$eval("a . b", scope)).toEqual(4); + expect(scope.$eval("a. b", scope)).toEqual(4); + expect(scope.$eval("a .b", scope)).toEqual(4); + expect(scope.$eval("a . \nb", scope)).toEqual(4); + }); + it('should resolve deeply nested paths (important for CSP mode)', function() { scope.a = {b: {c: {d: {e: {f: {g: {h: {i: {j: {k: {l: {m: {n: 'nooo!'}}}}}}}}}}}}}; expect(scope.$eval("a.b.c.d.e.f.g.h.i.j.k.l.m.n", scope)).toBe('nooo!');