Skip to content

Commit 7ea1a5b

Browse files
committed
fix(parser): string concatination with undefined model
Closes angular#988
1 parent 416a783 commit 7ea1a5b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ng/parse.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ var OPERATORS = {
55
'true':function(){return true;},
66
'false':function(){return false;},
77
undefined:noop,
8-
'+':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)+(isDefined(b)?b:0);},
8+
'+':function(self, locals, a,b){
9+
a=a(self, locals); b=b(self, locals);
10+
if (isDefined(a)) {
11+
if (isDefined(b)) return a+b;
12+
return a;
13+
}
14+
return isDefined(b)?b:undefined;},
915
'-':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
1016
'*':function(self, locals, a,b){return a(self, locals)*b(self, locals);},
1117
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},

test/ng/interpolateSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('$interpolate', function() {
1515

1616
it('should suppress falsy objects', inject(function($interpolate) {
1717
expect($interpolate('{{undefined}}')()).toEqual('');
18+
expect($interpolate('{{undefined+undefined}}')()).toEqual('');
1819
expect($interpolate('{{null}}')()).toEqual('');
1920
expect($interpolate('{{a.b}}')()).toEqual('');
2021
}));
@@ -31,6 +32,18 @@ describe('$interpolate', function() {
3132
expect($interpolate('Hello {{name}}!')($rootScope)).toEqual('Hello Misko!');
3233
}));
3334

35+
36+
it('should ignore undefined model', inject(function($interpolate) {
37+
expect($interpolate("Hello {{'World' + foo}}")()).toEqual('Hello World');
38+
}));
39+
40+
41+
it('should ignore undefined return value', inject(function($interpolate, $rootScope) {
42+
$rootScope.foo = function() {return undefined};
43+
expect($interpolate("Hello {{'World' + foo()}}")($rootScope)).toEqual('Hello World');
44+
}));
45+
46+
3447
describe('provider', function() {
3548
beforeEach(module(function($interpolateProvider) {
3649
$interpolateProvider.startSymbol('--');

0 commit comments

Comments
 (0)