Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(): allow spaces around dots for identifiers #8550

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
12 changes: 12 additions & 0 deletions test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!');
Expand Down