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

fix($resource): prevent URL template from collapsing into an empty string #5493

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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