fix($resource): allow params in hostname (except for IPv6 addresses)
This commit reverts the revert 02f045be8d.
This commit is contained in:
@@ -427,7 +427,7 @@ function shallowClearAndCopy(src, dst) {
|
||||
*/
|
||||
angular.module('ngResource', ['ng']).
|
||||
provider('$resource', function ResourceProvider() {
|
||||
var PROTOCOL_AND_DOMAIN_REGEX = /^https?:\/\/[^/]*/;
|
||||
var PROTOCOL_AND_IPV6_REGEX = /^https?:\/\/\[[^\]]*][^/]*/;
|
||||
|
||||
var provider = this;
|
||||
|
||||
@@ -575,7 +575,7 @@ angular.module('ngResource', ['ng']).
|
||||
url = actionUrl || self.template,
|
||||
val,
|
||||
encodedVal,
|
||||
protocolAndDomain = '';
|
||||
protocolAndIpv6 = '';
|
||||
|
||||
var urlParams = self.urlParams = {};
|
||||
forEach(url.split(/\W/), function(param) {
|
||||
@@ -590,8 +590,8 @@ angular.module('ngResource', ['ng']).
|
||||
}
|
||||
});
|
||||
url = url.replace(/\\:/g, ':');
|
||||
url = url.replace(PROTOCOL_AND_DOMAIN_REGEX, function(match) {
|
||||
protocolAndDomain = match;
|
||||
url = url.replace(PROTOCOL_AND_IPV6_REGEX, function(match) {
|
||||
protocolAndIpv6 = match;
|
||||
return '';
|
||||
});
|
||||
|
||||
@@ -628,7 +628,7 @@ angular.module('ngResource', ['ng']).
|
||||
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
|
||||
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
|
||||
// replace escaped `/\.` with `/.`
|
||||
config.url = protocolAndDomain + url.replace(/\/\\\./, '/.');
|
||||
config.url = protocolAndIpv6 + url.replace(/\/\\\./, '/.');
|
||||
|
||||
|
||||
// set params - delegate param encoding to $http
|
||||
|
||||
@@ -300,11 +300,35 @@ describe('basic usage', function() {
|
||||
});
|
||||
|
||||
it('should support IPv6 URLs', function() {
|
||||
var R = $resource('http://[2620:0:861:ed1a::1]/:ed1a/', {}, {}, {stripTrailingSlashes: false});
|
||||
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/foo/').respond({});
|
||||
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/').respond({});
|
||||
R.get({ed1a: 'foo'});
|
||||
R.get({});
|
||||
test('http://[2620:0:861:ed1a::1]', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]');
|
||||
test('http://[2620:0:861:ed1a::1]/', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/');
|
||||
test('http://[2620:0:861:ed1a::1]/:ed1a', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/foo');
|
||||
test('http://[2620:0:861:ed1a::1]/:ed1a', {}, 'http://[2620:0:861:ed1a::1]/');
|
||||
test('http://[2620:0:861:ed1a::1]/:ed1a/', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/foo/');
|
||||
test('http://[2620:0:861:ed1a::1]/:ed1a/', {}, 'http://[2620:0:861:ed1a::1]/');
|
||||
|
||||
// Helpers
|
||||
function test(templateUrl, params, actualUrl) {
|
||||
var R = $resource(templateUrl, null, null, {stripTrailingSlashes: false});
|
||||
$httpBackend.expect('GET', actualUrl).respond(null);
|
||||
R.get(params);
|
||||
}
|
||||
});
|
||||
|
||||
it('should support params in the `hostname` part of the URL', function() {
|
||||
test('http://:hostname', {hostname: 'foo.com'}, 'http://foo.com');
|
||||
test('http://:hostname/', {hostname: 'foo.com'}, 'http://foo.com/');
|
||||
test('http://:l2Domain.:l1Domain', {l1Domain: 'com', l2Domain: 'bar'}, 'http://bar.com');
|
||||
test('http://:l2Domain.:l1Domain/', {l1Domain: 'com', l2Domain: 'bar'}, 'http://bar.com/');
|
||||
test('http://127.0.0.:octet', {octet: 42}, 'http://127.0.0.42');
|
||||
test('http://127.0.0.:octet/', {octet: 42}, 'http://127.0.0.42/');
|
||||
|
||||
// Helpers
|
||||
function test(templateUrl, params, actualUrl) {
|
||||
var R = $resource(templateUrl, null, null, {stripTrailingSlashes: false});
|
||||
$httpBackend.expect('GET', actualUrl).respond(null);
|
||||
R.get(params);
|
||||
}
|
||||
});
|
||||
|
||||
it('should support overriding provider default trailing-slash stripping configuration', function() {
|
||||
|
||||
Reference in New Issue
Block a user