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

Commit f09b6aa

Browse files
lgalfasocaitp
authored andcommitted
fix($parse): do not use locals to resolve object properties
Do not use the locals when performing a field access in an angular expression. Closes #5838 Closes #5862
1 parent 8b395ff commit f09b6aa

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/ng/parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ Parser.prototype = {
707707
var getter = getterFn(field, this.options, this.text);
708708

709709
return extend(function(scope, locals, self) {
710-
return getter(self || object(scope, locals), locals);
710+
return getter(self || object(scope, locals));
711711
}, {
712712
assign: function(scope, value, locals) {
713713
return setter(object(scope, locals), field, value, parser.text, parser.options);

test/ng/parseSpec.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ describe('parser', function() {
358358
forEach([2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 42, 99], function(pathLength) {
359359
it('should resolve nested paths of length ' + pathLength, function() {
360360
// Create a nested object {x2: {x3: {x4: ... {x[n]: 42} ... }}}.
361-
var obj = 42;
361+
var obj = 42, locals = {};
362362
for (var i = pathLength; i >= 2; i--) {
363363
var newObj = {};
364364
newObj['x' + i] = obj;
@@ -371,6 +371,8 @@ describe('parser', function() {
371371
path += '.x' + i;
372372
}
373373
expect(scope.$eval(path)).toBe(42);
374+
locals['x' + pathLength] = 'not 42'
375+
expect(scope.$eval(path, locals)).toBe(42);
374376
});
375377
});
376378

@@ -938,6 +940,13 @@ describe('parser', function() {
938940
expect($parse('a.b')({a: {b: 0}}, {a: null})).toEqual(undefined);
939941
expect($parse('a.b.c')({a: null}, {a: {b: {c: 1}}})).toEqual(1);
940942
}));
943+
944+
it('should not use locals to resolve object properties', inject(function($parse) {
945+
expect($parse('a[0].b')({a: [ {b : 'scope'} ]}, {b : 'locals'})).toBe('scope');
946+
expect($parse('a[0]["b"]')({a: [ {b : 'scope'} ]}, {b : 'locals'})).toBe('scope');
947+
expect($parse('a[0][0].b')({a: [[{b : 'scope'}]]}, {b : 'locals'})).toBe('scope');
948+
expect($parse('a[0].b.c')({a: [ {b: {c: 'scope'}}] }, {b : {c: 'locals'} })).toBe('scope');
949+
}));
941950
});
942951

943952
describe('literal', function() {

0 commit comments

Comments
 (0)