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

Commit 4909d1d

Browse files
Benjamín Eidelmanmhevery
Benjamín Eidelman
authored andcommitted
fix($resource): allow falsy values in URL parameters
Close #1212 when a param value was 0 (or false) it was ignored and removed from url. after this fix that only happens if the value is undefined or null.
1 parent 7079ff5 commit 4909d1d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/ngResource/resource.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ angular.module('ngResource', ['ng']).
285285

286286
params = params || {};
287287
forEach(this.urlParams, function(_, urlParam){
288-
if (val = (params[urlParam] || self.defaults[urlParam])) {
288+
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
289+
if (isDefined(val) && val !== null) {
289290
encodedVal = encodeUriSegment(val);
290291
url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
291292
} else {

test/ngResource/resourceSpec.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,22 @@ describe("resource", function() {
5151
it('should ignore slashes of undefinend parameters', function() {
5252
var R = $resource('/Path/:a/:b/:c');
5353

54-
$httpBackend.when('GET').respond('{}');
55-
$httpBackend.expect('GET', '/Path');
56-
$httpBackend.expect('GET', '/Path/1');
57-
$httpBackend.expect('GET', '/Path/2/3');
58-
$httpBackend.expect('GET', '/Path/4/5');
59-
$httpBackend.expect('GET', '/Path/6/7/8');
54+
$httpBackend.when('GET', '/Path').respond('{}');
55+
$httpBackend.when('GET', '/Path/0').respond('{}');
56+
$httpBackend.when('GET', '/Path/false').respond('{}');
57+
$httpBackend.when('GET', '/Path').respond('{}');
58+
$httpBackend.when('GET', '/Path/').respond('{}');
59+
$httpBackend.when('GET', '/Path/1').respond('{}');
60+
$httpBackend.when('GET', '/Path/2/3').respond('{}');
61+
$httpBackend.when('GET', '/Path/4/5').respond('{}');
62+
$httpBackend.when('GET', '/Path/6/7/8').respond('{}');
6063

6164
R.get({});
65+
R.get({a:0});
66+
R.get({a:false});
67+
R.get({a:null});
68+
R.get({a:undefined});
69+
R.get({a:''});
6270
R.get({a:1});
6371
R.get({a:2, b:3});
6472
R.get({a:4, c:5});

0 commit comments

Comments
 (0)