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 #5455
Closes #5493
This commit is contained in:
Gias Kay Lee 2013-12-20 23:15:46 +08:00 committed by Igor Minar
parent 01c5be4681
commit 131e4014b8
2 changed files with 8 additions and 1 deletions

View file

@ -401,7 +401,7 @@ angular.module('ngResource', ['ng']).
});
// strip trailing slashes and set the url
url = url.replace(/\/+$/, '');
url = url.replace(/\/+$/, '') || '/';
// then replace collapse `/.` if found in the last URL path segment before the query
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
url = url.replace(/\/\.(?=\w+($|\?))/, '.');

View file

@ -150,6 +150,13 @@ describe("resource", function() {
R.get({a:6, b:7, c:8});
});
it('should not collapsed the url into an empty string', function() {
var R = $resource('/:foo/:bar/');
$httpBackend.when('GET', '/').respond('{}');
R.get({});
});
it('should support escaping colons in url template', function() {
var R = $resource('http://localhost\\:8080/Path/:a/\\:stillPath/:b');