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

Commit

Permalink
fix($resource): prevent URL template from collapsing into an empty st…
Browse files Browse the repository at this point in the history
…ring

if url template would result in an empty string, we should make a request
to '/' instead.

Closes #5455
Closes #5493
  • Loading branch information
Gias Kay Lee authored and IgorMinar committed Jan 3, 2014
1 parent 01c5be4 commit 131e401
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+($|\?))/, '.');
Expand Down
7 changes: 7 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 131e401

Please sign in to comment.