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

Commit b7e1fb0

Browse files
Fredrik Bonandermhevery
Fredrik Bonander
authored andcommitted
fix(resource): Update RegExp to allow urlParams with out leading slash
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.
1 parent 755beb2 commit b7e1fb0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ angular.module('ngResource', ['ng']).
308308
this.defaults = defaults || {};
309309
var urlParams = this.urlParams = {};
310310
forEach(template.split(/\W/), function(param){
311-
if (param && template.match(new RegExp("[^\\\\]:" + param + "\\W"))) {
311+
if (param && (new RegExp("(^|[^\\\\]):" + param + "\\W").test(template))) {
312312
urlParams[param] = true;
313313
}
314314
});

test/ngResource/resourceSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ describe("resource", function() {
129129
R.get({a: 'doh@fo o', ':bar': '$baz@1', '!do&h': 'g=a h'});
130130
});
131131

132+
it('should allow relative paths in resource url', function () {
133+
var R = $resource(':relativePath');
134+
$httpBackend.expect('GET', 'data.json').respond('{}');
135+
R.get({ relativePath: 'data.json' });
136+
});
137+
138+
it('should handle + in url params', function () {
139+
var R = $resource('/api/myapp/:myresource?from=:from&to=:to&histlen=:histlen');
140+
$httpBackend.expect('GET', '/api/myapp/pear+apple?from=2012-04-01&to=2012-04-29&histlen=3').respond('{}');
141+
R.get({ myresource: 'pear+apple', from : '2012-04-01', to : '2012-04-29', histlen : 3 });
142+
});
143+
132144

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

0 commit comments

Comments
 (0)