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

Commit b94ca12

Browse files
leosterapetebacondarwin
authored andcommitted
feat($resource): support an unescaped URL port
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
1 parent 22a9b1a commit b94ca12

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/ngResource/resource.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
*
3232
* @param {string} url A parametrized URL template with parameters prefixed by `:` as in
3333
* `/user/:username`. If you are using a URL with a port number (e.g.
34-
* `http://example.com:8080/api`), you'll need to escape the colon character before the port
35-
* number, like this: `$resource('http://example.com\\:8080/api')`.
34+
* `http://example.com:8080/api`), it will be respected.
3635
*
3736
* If you are using a url with a suffix, just add the suffix, like this:
3837
* `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')
@@ -345,7 +344,7 @@ angular.module('ngResource', ['ng']).
345344

346345
var urlParams = self.urlParams = {};
347346
forEach(url.split(/\W/), function(param){
348-
if (param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
347+
if (!(new RegExp("^\\d+$").test(param)) && param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
349348
urlParams[param] = true;
350349
}
351350
});

test/ngResource/resourceSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ describe("resource", function() {
106106
R.get({a: 'foo', b: 'bar'});
107107
});
108108

109+
it('should support an unescaped url', function() {
110+
var R = $resource('http://localhost:8080/Path/:a');
111+
112+
$httpBackend.expect('GET', 'http://localhost:8080/Path/foo').respond();
113+
R.get({a: 'foo'});
114+
});
115+
109116

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

0 commit comments

Comments
 (0)