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

Ignore parameters starting with digit in $resource #3150

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
* and you are ready to get started!
*
* @param {string} url A parametrized URL template with parameters prefixed by `:` as in
* `/user/:username`. If you are using a URL with a port number (e.g.
* `http://example.com:8080/api`), you'll need to escape the colon character before the port
* number, like this: `$resource('http://example.com\\:8080/api')`.
* `/user/:username`.
*
* If you are using a url with a suffix, just add the suffix, like this:
* `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')
Expand Down Expand Up @@ -346,7 +344,9 @@ angular.module('ngResource', ['ng']).
var urlParams = self.urlParams = {};
forEach(url.split(/\W/), function(param){
if (param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
urlParams[param] = true;
if(new RegExp("^[^0-9].*$").test(param)) {
urlParams[param] = true;
}
}
});
url = url.replace(/\\:/g, ':');
Expand Down
22 changes: 22 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ describe("resource", function() {
R.get({a:6, b:7, c:8});
});

it('should ignore parameters starting with digit', function() {
var R = $resource('http://www.example.com:8080/Path/:4a/:a');

$httpBackend.when('GET', 'http://www.example.com:8080/Path/:4a').respond('{}');
$httpBackend.when('GET', 'http://www.example.com:8080/Path/:4a/0').respond('{}');
$httpBackend.when('GET', 'http://www.example.com:8080/Path/:4a?8080=1').respond('{}');

R.get({});
R.get({a:0});
R.get({"8080":1});
});

it('should not ignore parameters that contain digits but do not start with digit', function() {
var R = $resource('/Path/:a42');

$httpBackend.when('GET', '/Path').respond('{}');
$httpBackend.when('GET', '/Path/7').respond('{}');

R.get({});
R.get({a42: 7});
});

it('should not ignore leading slashes of undefinend parameters that have non-slash trailing sequence', function() {
var R = $resource('/Path/:a.foo/:b.bar/:c.baz');

Expand Down