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

Commit 06ed8ef

Browse files
fredrikbonandermhevery
authored andcommitted
fix($resource): Route constructor, updated RegExp
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 2f437e8 commit 06ed8ef

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ angular.module('ngResource', ['ng']).
290290
this.defaults = defaults || {};
291291
var urlParams = this.urlParams = {};
292292
forEach(template.split(/\W/), function(param){
293-
if (param && template.match(new RegExp("[^\\\\]:" + param + "\\W"))) {
293+
if (param && (new RegExp("((\\w|\\/|^)(?!\\\\:" + param + ")):" + param + "\\W")).test(template)) {
294294
urlParams[param] = true;
295295
}
296296
});

test/ngResource/resourceSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ 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(':a');
134+
$httpBackend.expect('GET', 'data.json').respond('{}');
135+
R.get({ a: 'data.json' });
136+
});
137+
132138

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

0 commit comments

Comments
 (0)