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

Commit cefbcd4

Browse files
jrschumacherIgorMinar
authored andcommitted
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`
1 parent f9b897d commit cefbcd4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ angular.module('ngResource', ['ng']).
392392
actionParams = extend({}, paramDefaults, actionParams);
393393
forEach(actionParams, function(value, key){
394394
if (isFunction(value)) { value = value(); }
395-
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
395+
ids[key] = value && value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
396396
});
397397
return ids;
398398
}

test/ngResource/resourceSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ describe("resource", function() {
205205
});
206206

207207

208+
it('should not throw TypeError on null default params', function() {
209+
$httpBackend.expect('GET', '/Path?').respond('{}');
210+
var R = $resource('/Path', {param: null}, {get: {method: 'GET'}});
211+
212+
expect(function() {
213+
R.get({});
214+
}).not.toThrow();
215+
});
216+
217+
208218
it('should handle multiple params with same name', function() {
209219
var R = $resource('/:id/:id');
210220

0 commit comments

Comments
 (0)