From 78068ce6236df0ce70ee6b5702de2daff05b6f4c Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Tue, 14 May 2013 02:41:01 -0300 Subject: [PATCH] feat($resource): support an unescaped url Added new regex to test the url parameters with: - if the parameter consists only of numbers, then it's a port --- src/ngResource/resource.js | 5 ++--- test/ngResource/resourceSpec.js | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 3eb4e79e4b13..ac6211bdfd49 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -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. * * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in * `actions` methods. If any of the parameter value is a function, it will be executed every time @@ -331,7 +330,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; } }); diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index 225f96a165ba..b6c80876b3f9 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -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');