From cefbcd470d4c9020cc3487b2326d45058ef831e2 Mon Sep 17 00:00:00 2001 From: Ryan Schumacher Date: Wed, 3 Apr 2013 10:40:16 -0500 Subject: [PATCH] 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` --- src/ngResource/resource.js | 2 +- test/ngResource/resourceSpec.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index a2e915e84f64..c165ffab1422 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 916fa455a039..ec7f1476b580 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');