fix($resource): null default param results in TypeError

Fixes issue when setting a default param as `null` error
`TypeError: Cannot read property 'charAt' of null`
This commit is contained in:
Ryan Schumacher 2013-04-03 10:40:16 -05:00 committed by Igor Minar
parent f9b897de4b
commit cefbcd470d
2 changed files with 11 additions and 1 deletions

View file

@ -392,7 +392,7 @@ angular.module('ngResource', ['ng']).
actionParams = extend({}, paramDefaults, actionParams);
forEach(actionParams, function(value, key){
if (isFunction(value)) { value = value(); }
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
ids[key] = value && value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
});
return ids;
}

View file

@ -205,6 +205,16 @@ describe("resource", function() {
});
it('should not throw TypeError on null default params', function() {
$httpBackend.expect('GET', '/Path?').respond('{}');
var R = $resource('/Path', {param: null}, {get: {method: 'GET'}});
expect(function() {
R.get({});
}).not.toThrow();
});
it('should handle multiple params with same name', function() {
var R = $resource('/:id/:id');