aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Schumacher2013-04-03 10:40:16 -0500
committerIgor Minar2013-05-16 14:26:08 -0700
commitcefbcd470d4c9020cc3487b2326d45058ef831e2 (patch)
treeaafaaf17f9b3d1743e897f8dc2a3e07de6c658d0
parentf9b897de4b5cc438515cbb54519fbdf6242f5858 (diff)
downloadangular.js-cefbcd470d4c9020cc3487b2326d45058ef831e2.tar.bz2
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`
-rw-r--r--src/ngResource/resource.js2
-rw-r--r--test/ngResource/resourceSpec.js10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index a2e915e8..c165ffab 100644
--- a/src/ngResource/resource.js
+++ b/src/ngResource/resource.js
@@ -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;
}
diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js
index 916fa455..ec7f1476 100644
--- a/test/ngResource/resourceSpec.js
+++ b/test/ngResource/resourceSpec.js
@@ -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');