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

Commit e506073

Browse files
petrovalexmhevery
authored andcommittedSep 4, 2012
fix(parser): string concatination with undefined model
Closes #988
1 parent 45180ef commit e506073

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
 

‎src/ng/parse.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ 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)) {
12+
return a + b;
13+
}
14+
return a;
15+
}
16+
return isDefined(b)?b:undefined;},
917
'-':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
1018
'*':function(self, locals, a,b){return a(self, locals)*b(self, locals);},
1119
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},

‎test/ng/interpolateSpec.js

+26
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
}));
@@ -55,6 +56,31 @@ describe('$interpolate', function() {
5556
}));
5657

5758

59+
it('should ignore undefined model', inject(function($interpolate) {
60+
expect($interpolate("Hello {{'World' + foo}}")()).toEqual('Hello World');
61+
}));
62+
63+
64+
it('should ignore undefined return value', inject(function($interpolate, $rootScope) {
65+
$rootScope.foo = function() {return undefined};
66+
expect($interpolate("Hello {{'World' + foo()}}")($rootScope)).toEqual('Hello World');
67+
}));
68+
69+
70+
describe('provider', function() {
71+
beforeEach(module(function($interpolateProvider) {
72+
$interpolateProvider.startSymbol('--');
73+
$interpolateProvider.endSymbol('--');
74+
}));
75+
76+
it('should not get confused with same markers', inject(function($interpolate) {
77+
expect($interpolate('---').parts).toEqual(['---']);
78+
expect($interpolate('----')()).toEqual('');
79+
expect($interpolate('--1--')()).toEqual('1');
80+
}));
81+
});
82+
83+
5884
describe('parseBindings', function() {
5985
it('should Parse Text With No Bindings', inject(function($interpolate) {
6086
var parts = $interpolate("a").parts;

0 commit comments

Comments
 (0)