Skip to content

Commit a931154

Browse files
committed
covered the situation when undefined parameters are not the end of the url
1 parent 721d135 commit a931154

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/ngResource/resource.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,17 @@ angular.module('ngResource', ['ng']).
279279
url: function(params) {
280280
var self = this,
281281
url = this.template,
282+
val,
282283
encodedVal;
283284

284285
params = params || {};
285286
forEach(this.urlParams, function(_, urlParam){
286-
encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || "");
287-
url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
287+
if (val = (params[urlParam] || self.defaults[urlParam])) {
288+
encodedVal = encodeUriSegment(val);
289+
url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
290+
} else {
291+
url = url.replace(new RegExp("/?:" + urlParam + "(\\W)", "g"), '$1');
292+
}
288293
});
289294
url = url.replace(/\/?#$/, '');
290295
var query = [];

test/ngResource/resourceSpec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ describe("resource", function() {
4848
$httpBackend.expect('GET', '/Path');
4949
$httpBackend.expect('GET', '/Path/1');
5050
$httpBackend.expect('GET', '/Path/2/3');
51-
$httpBackend.expect('GET', '/Path/4/5/6');
51+
$httpBackend.expect('GET', '/Path/4/5');
52+
$httpBackend.expect('GET', '/Path/6/7/8');
5253

5354
R.get({});
5455
R.get({a:1});
5556
R.get({a:2, b:3});
56-
R.get({a:4, b:5, c:6});
57+
R.get({a:4, c:5});
58+
R.get({a:6, b:7, c:8});
5759
});
5860

5961

0 commit comments

Comments
 (0)