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

Commit 8943c93

Browse files
committed
fix($parse): set null reference properties to undefined
When there is an expression of the form * true && a.b.c * true && a() * true && a()() * false || a.b.c * false || a() * false || a()() where `a == null` Closes #12099
1 parent 91b6022 commit 8943c93

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/ng/parse.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ ASTCompiler.prototype = {
953953
left = nameId && (nameId.context = this.nextId()) || this.nextId();
954954
intoId = intoId || this.nextId();
955955
self.recurse(ast.object, left, undefined, function() {
956+
self.assign(intoId, 'undefined');
956957
self.if_(self.notNull(left), function() {
957958
if (ast.computed) {
958959
right = self.nextId();
@@ -982,10 +983,8 @@ ASTCompiler.prototype = {
982983
nameId.name = ast.property.name;
983984
}
984985
}
985-
recursionFn(intoId);
986-
}, function() {
987-
self.assign(intoId, 'undefined');
988986
});
987+
recursionFn(intoId);
989988
}, !!create);
990989
break;
991990
case AST.CallExpression:
@@ -1006,6 +1005,7 @@ ASTCompiler.prototype = {
10061005
left = {};
10071006
args = [];
10081007
self.recurse(ast.callee, right, left, function() {
1008+
self.assign(intoId, 'undefined');
10091009
self.if_(self.notNull(right), function() {
10101010
self.addEnsureSafeFunction(right);
10111011
forEach(ast.arguments, function(expr) {
@@ -1023,8 +1023,8 @@ ASTCompiler.prototype = {
10231023
}
10241024
expression = self.ensureSafeObject(expression);
10251025
self.assign(intoId, expression);
1026-
recursionFn(intoId);
10271026
});
1027+
recursionFn(intoId);
10281028
});
10291029
}
10301030
break;

test/ng/parseSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -1746,9 +1746,15 @@ describe('parser', function() {
17461746
expect(scope.$eval("0||2")).toEqual(0 || 2);
17471747
expect(scope.$eval("0||1&&2")).toEqual(0 || 1 && 2);
17481748
expect(scope.$eval("true&&a")).toEqual(true && undefined);
1749+
expect(scope.$eval("true&&a()")).toEqual(true && undefined);
1750+
expect(scope.$eval("true&&a()()")).toEqual(true && undefined);
17491751
expect(scope.$eval("true&&a.b")).toEqual(true && undefined);
1752+
expect(scope.$eval("true&&a.b.c")).toEqual(true && undefined);
17501753
expect(scope.$eval("false||a")).toEqual(false || undefined);
1754+
expect(scope.$eval("false||a()")).toEqual(false || undefined);
1755+
expect(scope.$eval("false||a()()")).toEqual(false || undefined);
17511756
expect(scope.$eval("false||a.b")).toEqual(false || undefined);
1757+
expect(scope.$eval("false||a.b.c")).toEqual(false || undefined);
17521758
});
17531759

17541760
it('should parse ternary', function() {

0 commit comments

Comments
 (0)