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

fix($resource) Route constructor, updated RegExp #1402

Closed
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 @@ -290,7 +290,7 @@ angular.module('ngResource', ['ng']).
this.defaults = defaults || {};
var urlParams = this.urlParams = {};
forEach(template.split(/\W/), function(param){
if (param && template.match(new RegExp("[^\\\\]:" + param + "\\W"))) {
if (param && (new RegExp("(^|[^\\\\]):" + param + "\\W").test(template))) {
urlParams[param] = true;
}
});
Expand Down
12 changes: 12 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ describe("resource", function() {
R.get({a: 'doh@fo o', ':bar': '$baz@1', '!do&h': 'g=a h'});
});

it('should allow relative paths in resource url', function () {
var R = $resource(':relativePath');
$httpBackend.expect('GET', 'data.json').respond('{}');
R.get({ relativePath: 'data.json' });
});

it('should handle + in url params', function () {
var R = $resource('/api/myapp/:myresource?from=:from&to=:to&histlen=:histlen');
$httpBackend.expect('GET', '/api/myapp/pear+apple?from=2012-04-01&to=2012-04-29&histlen=3').respond('{}');
R.get({ myresource: 'pear+apple', from : '2012-04-01', to : '2012-04-29', histlen : 3 });
});


it('should encode & in url params', function() {
var R = $resource('/Path/:a');
Expand Down