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

Commit

Permalink
fix(resource): Update RegExp to allow urlParams with out leading slash
Browse files Browse the repository at this point in the history
Will allow reoucese to be loaded from a relative path
Example:
var R = $resource(':path');
R.get({ path : 'data.json' });

Example usage:
Load resources in applications not using webserver, ie local webapp in 
on a tablet.
  • Loading branch information
Fredrik Bonander authored and mhevery committed Feb 14, 2013
1 parent 755beb2 commit b7e1fb0
Show file tree
Hide file tree
Showing 2 changed files with 13 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 @@ -308,7 +308,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

0 comments on commit b7e1fb0

Please sign in to comment.