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

Commit 0d52ff0

Browse files
petrovalexmhevery
authored andcommitted
fix($parser): string concatination with undefined model
Closes #988
1 parent baf52e9 commit 0d52ff0

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
}));
@@ -32,6 +33,31 @@ describe('$interpolate', function() {
3233
}));
3334

3435

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+
47+
describe('provider', function() {
48+
beforeEach(module(function($interpolateProvider) {
49+
$interpolateProvider.startSymbol('--');
50+
$interpolateProvider.endSymbol('--');
51+
}));
52+
53+
it('should not get confused with same markers', inject(function($interpolate) {
54+
expect($interpolate('---').parts).toEqual(['---']);
55+
expect($interpolate('----')()).toEqual('');
56+
expect($interpolate('--1--')()).toEqual('1');
57+
}));
58+
});
59+
60+
3561
describe('parseBindings', function() {
3662
it('should Parse Text With No Bindings', inject(function($interpolate) {
3763
var parts = $interpolate("a").parts;

0 commit comments

Comments
 (0)