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

fix($parse): do not use locals on field access #5862

Closed
wants to merge 1 commit into from
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
2 changes: 1 addition & 1 deletion src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ Parser.prototype = {
var getter = getterFn(field, this.options, this.text);

return extend(function(scope, locals, self) {
return getter(self || object(scope, locals), locals);
return getter(self || object(scope, locals));
}, {
assign: function(scope, value, locals) {
return setter(object(scope, locals), field, value, parser.text, parser.options);
Expand Down
11 changes: 10 additions & 1 deletion test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ describe('parser', function() {
forEach([2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 42, 99], function(pathLength) {
it('should resolve nested paths of length ' + pathLength, function() {
// Create a nested object {x2: {x3: {x4: ... {x[n]: 42} ... }}}.
var obj = 42;
var obj = 42, locals = {};
for (var i = pathLength; i >= 2; i--) {
var newObj = {};
newObj['x' + i] = obj;
Expand All @@ -371,6 +371,8 @@ describe('parser', function() {
path += '.x' + i;
}
expect(scope.$eval(path)).toBe(42);
locals['x' + pathLength] = 'not 42'
expect(scope.$eval(path, locals)).toBe(42);
});
});

Expand Down Expand Up @@ -938,6 +940,13 @@ describe('parser', function() {
expect($parse('a.b')({a: {b: 0}}, {a: null})).toEqual(undefined);
expect($parse('a.b.c')({a: null}, {a: {b: {c: 1}}})).toEqual(1);
}));

it('should use context resolution', inject(function($parse) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it('should not use locals to resolve object fields',....

expect($parse('a[0].b')({a: [ {b : 'scope'} ]}, {b : 'locals'})).toBe('scope');
expect($parse('a[0]["b"]')({a: [ {b : 'scope'} ]}, {b : 'locals'})).toBe('scope');
expect($parse('a[0][0].b')({a: [[{b : 'scope'}]]}, {b : 'locals'})).toBe('scope');
expect($parse('a[0].b.c')({a: [ {b: {c: 'scope'}}] }, {b : {c: 'locals'} })).toBe('scope');
}));
});

describe('literal', function() {
Expand Down