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']).
|
angular.module('ngResource', ['ng']).
|
||||||
provider('$resource', function ResourceProvider() {
|
provider('$resource', function ResourceProvider() {
|
||||||
var PROTOCOL_AND_DOMAIN_REGEX = /^https?:\/\/[^/]*/;
|
var PROTOCOL_AND_IPV6_REGEX = /^https?:\/\/\[[^\]]*][^/]*/;
|
||||||
|
|
||||||
var provider = this;
|
var provider = this;
|
||||||
|
|
||||||
@@ -575,7 +575,7 @@ angular.module('ngResource', ['ng']).
|
|||||||
url = actionUrl || self.template,
|
url = actionUrl || self.template,
|
||||||
val,
|
val,
|
||||||
encodedVal,
|
encodedVal,
|
||||||
protocolAndDomain = '';
|
protocolAndIpv6 = '';
|
||||||
|
|
||||||
var urlParams = self.urlParams = {};
|
var urlParams = self.urlParams = {};
|
||||||
forEach(url.split(/\W/), function(param) {
|
forEach(url.split(/\W/), function(param) {
|
||||||
@@ -590,8 +590,8 @@ angular.module('ngResource', ['ng']).
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
url = url.replace(/\\:/g, ':');
|
url = url.replace(/\\:/g, ':');
|
||||||
url = url.replace(PROTOCOL_AND_DOMAIN_REGEX, function(match) {
|
url = url.replace(PROTOCOL_AND_IPV6_REGEX, function(match) {
|
||||||
protocolAndDomain = match;
|
protocolAndIpv6 = match;
|
||||||
return '';
|
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`
|
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
|
||||||
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
|
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
|
||||||
// replace escaped `/\.` with `/.`
|
// replace escaped `/\.` with `/.`
|
||||||
config.url = protocolAndDomain + url.replace(/\/\\\./, '/.');
|
config.url = protocolAndIpv6 + url.replace(/\/\\\./, '/.');
|
||||||
|
|
||||||
|
|
||||||
// set params - delegate param encoding to $http
|
// set params - delegate param encoding to $http
|
||||||
|
|||||||
@@ -300,11 +300,35 @@ describe('basic usage', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should support IPv6 URLs', function() {
|
it('should support IPv6 URLs', function() {
|
||||||
var R = $resource('http://[2620:0:861:ed1a::1]/:ed1a/', {}, {}, {stripTrailingSlashes: false});
|
test('http://[2620:0:861:ed1a::1]', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]');
|
||||||
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/foo/').respond({});
|
test('http://[2620:0:861:ed1a::1]/', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/');
|
||||||
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/').respond({});
|
test('http://[2620:0:861:ed1a::1]/:ed1a', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/foo');
|
||||||
R.get({ed1a: 'foo'});
|
test('http://[2620:0:861:ed1a::1]/:ed1a', {}, 'http://[2620:0:861:ed1a::1]/');
|
||||||
R.get({});
|
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() {
|
it('should support overriding provider default trailing-slash stripping configuration', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user