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

Commit

Permalink
fix($resource): null default param results in TypeError
Browse files Browse the repository at this point in the history
Fixes issue when setting a default param as `null` error
`TypeError: Cannot read property 'charAt' of null`
  • Loading branch information
jrschumacher authored and IgorMinar committed May 16, 2013
1 parent f9b897d commit cefbcd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit cefbcd4

Please sign in to comment.