Skip to content

Commit 70f2464

Browse files
Gias Kay Leejamesdaily
Gias Kay Lee
authored andcommitted
fix($resource): prevent URL template from collapsing into an empty string
if url template would result in an empty string, we should make a request to '/' instead. Closes angular#5455 Closes angular#5493
1 parent 415bf41 commit 70f2464

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ angular.module('ngResource', ['ng']).
401401
});
402402

403403
// strip trailing slashes and set the url
404-
url = url.replace(/\/+$/, '');
404+
url = url.replace(/\/+$/, '') || '/';
405405
// then replace collapse `/.` if found in the last URL path segment before the query
406406
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
407407
url = url.replace(/\/\.(?=\w+($|\?))/, '.');

test/ngResource/resourceSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ describe("resource", function() {
150150
R.get({a:6, b:7, c:8});
151151
});
152152

153+
it('should not collapsed the url into an empty string', function() {
154+
var R = $resource('/:foo/:bar/');
155+
156+
$httpBackend.when('GET', '/').respond('{}');
157+
158+
R.get({});
159+
});
153160

154161
it('should support escaping colons in url template', function() {
155162
var R = $resource('http://localhost\\:8080/Path/:a/\\:stillPath/:b');

0 commit comments

Comments
 (0)