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

fix(parser): string concatination with undefined model #991

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
8 changes: 7 additions & 1 deletion src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ var OPERATORS = {
'true':function(){return true;},
'false':function(){return false;},
undefined:noop,
'+':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)+(isDefined(b)?b:0);},
'+':function(self, locals, a,b){
a=a(self, locals); b=b(self, locals);
if (isDefined(a)) {
if (isDefined(b)) return a+b;
return a;
}
return isDefined(b)?b:undefined;},
'-':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
'*':function(self, locals, a,b){return a(self, locals)*b(self, locals);},
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},
Expand Down
13 changes: 13 additions & 0 deletions test/ng/interpolateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('$interpolate', function() {

it('should suppress falsy objects', inject(function($interpolate) {
expect($interpolate('{{undefined}}')()).toEqual('');
expect($interpolate('{{undefined+undefined}}')()).toEqual('');
expect($interpolate('{{null}}')()).toEqual('');
expect($interpolate('{{a.b}}')()).toEqual('');
}));
Expand All @@ -31,6 +32,18 @@ describe('$interpolate', function() {
expect($interpolate('Hello {{name}}!')($rootScope)).toEqual('Hello Misko!');
}));


it('should ignore undefined model', inject(function($interpolate) {
expect($interpolate("Hello {{'World' + foo}}")()).toEqual('Hello World');
}));


it('should ignore undefined return value', inject(function($interpolate, $rootScope) {
$rootScope.foo = function() {return undefined};
expect($interpolate("Hello {{'World' + foo()}}")($rootScope)).toEqual('Hello World');
}));


describe('provider', function() {
beforeEach(module(function($interpolateProvider) {
$interpolateProvider.startSymbol('--');
Expand Down