Skip to content
This repository was 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 1 commit
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
Next Next commit
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.
  • Loading branch information
fredrikbonander committed Sep 21, 2012
commit 9c8c34b63b9035849cddbf8fa92faf45f2ba8ac6
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,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;
}
});
Expand Down
6 changes: 6 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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');
Expand Down