diff options
| author | Fredrik Bonander | 2012-09-21 13:39:45 +0200 |
|---|---|---|
| committer | Misko Hevery | 2013-01-18 21:28:15 -0800 |
| commit | 06ed8ef0127bf80610eba17b5021d1f483d0b0bf (patch) | |
| tree | a0b8d67d78d3d621318159927dd81836361ecefe | |
| parent | 2f437e89781cb2b449abb685e36b26ca1cf0fff5 (diff) | |
| download | angular.js-06ed8ef0127bf80610eba17b5021d1f483d0b0bf.tar.bz2 | |
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.
| -rw-r--r-- | src/ngResource/resource.js | 2 | ||||
| -rw-r--r-- | test/ngResource/resourceSpec.js | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 7e26a6a4..549226a2 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -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("((\\w|\\/|^)(?!\\\\:" + param + ")):" + param + "\\W")).test(template)) { urlParams[param] = true; } }); diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index 33dc6d5b..cf3b886b 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -129,6 +129,12 @@ 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(':a'); + $httpBackend.expect('GET', 'data.json').respond('{}'); + R.get({ a: 'data.json' }); + }); + it('should encode & in url params', function() { var R = $resource('/Path/:a'); |
