Skip to content

Commit bbf0ad8

Browse files
fix(): allow spaces around dots for identifiers
Fixes angular#4613
1 parent e4e7e94 commit bbf0ad8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/ng/parse.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,17 @@ Lexer.prototype = {
263263
var ident = '';
264264
var start = this.index;
265265

266-
var lastDot, peekIndex, methodName, ch;
266+
var lastDot, justSeenADot, peekIndex, methodName, ch;
267267

268268
while (this.index < this.text.length) {
269269
ch = this.text.charAt(this.index);
270270
if (ch === '.' || this.isIdent(ch) || this.isNumber(ch)) {
271-
if (ch === '.') lastDot = this.index;
271+
if (justSeenADot = ch === '.') lastDot = this.index;
272272
ident += ch;
273273
} else {
274-
break;
274+
if (!(this.isWhitespace(ch) && justSeenADot)) {
275+
break;
276+
}
275277
}
276278
this.index++;
277279
}

test/ng/parseSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ describe('parser', function() {
7171
expect(tokens[i].string).toEqual('d"e');
7272
});
7373

74+
it('should tokenize identifiers with spaces after dots', function () {
75+
expect(lex('foo. bar')[0].text).toEqual('foo.bar');
76+
});
77+
7478
it('should tokenize undefined', function() {
7579
var tokens = lex("undefined");
7680
var i = 0;
@@ -349,6 +353,14 @@ describe('parser', function() {
349353
expect(scope.$eval("x.y.z", scope)).not.toBeDefined();
350354
});
351355

356+
it('should handle white-spaces around dots in paths', function () {
357+
scope.a = {b: 4};
358+
expect(scope.$eval("a . b", scope)).toEqual(4);
359+
expect(scope.$eval("a. b", scope)).toEqual(4);
360+
expect(scope.$eval("a .b", scope)).toEqual(4);
361+
expect(scope.$eval("a . \nb", scope)).toEqual(4);
362+
});
363+
352364
it('should resolve deeply nested paths (important for CSP mode)', function() {
353365
scope.a = {b: {c: {d: {e: {f: {g: {h: {i: {j: {k: {l: {m: {n: 'nooo!'}}}}}}}}}}}}};
354366
expect(scope.$eval("a.b.c.d.e.f.g.h.i.j.k.l.m.n", scope)).toBe('nooo!');

0 commit comments

Comments
 (0)