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

Commit

Permalink
feat($resource): support an unescaped URL port
Browse files Browse the repository at this point in the history
The colon character is used to identify parameters in $resource.
This meant that we had to escape the colon used in a port.
It turns out that this is not necessary if we assume that parameter
names cannot consist of only digits.
If the parameter consists only of numbers, then it's a port.

Closes #2778
  • Loading branch information
leostera authored and petebacondarwin committed Jul 12, 2013
1 parent 22a9b1a commit b94ca12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
*
* @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')`.
* `http://example.com:8080/api`), it will be respected.
*
* 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 @@ -345,7 +344,7 @@ angular.module('ngResource', ['ng']).

var urlParams = self.urlParams = {};
forEach(url.split(/\W/), function(param){
if (param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
if (!(new RegExp("^\\d+$").test(param)) && param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
urlParams[param] = true;
}
});
Expand Down
7 changes: 7 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ describe("resource", function() {
R.get({a: 'foo', b: 'bar'});
});

it('should support an unescaped url', function() {
var R = $resource('http://localhost:8080/Path/:a');

$httpBackend.expect('GET', 'http://localhost:8080/Path/foo').respond();
R.get({a: 'foo'});
});


it('should correctly encode url params', function() {
var R = $resource('/Path/:a');
Expand Down

0 comments on commit b94ca12

Please sign in to comment.