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

Commit b643f0d

Browse files
committed
fix(ngResources): support IPv6 URLs
Do not confuse IPv6 URLs domains and resource parameters. Closes #12512 Closes #12532
1 parent 01dd588 commit b643f0d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/ngResource/resource.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ function shallowClearAndCopy(src, dst) {
348348
*/
349349
angular.module('ngResource', ['ng']).
350350
provider('$resource', function() {
351+
var PROTOCOL_AND_DOMAIN_REGEX = /^https?:\/\/[^\/]*/;
351352
var provider = this;
352353

353354
this.defaults = {
@@ -422,7 +423,8 @@ angular.module('ngResource', ['ng']).
422423
var self = this,
423424
url = actionUrl || self.template,
424425
val,
425-
encodedVal;
426+
encodedVal,
427+
protocolAndDomain = '';
426428

427429
var urlParams = self.urlParams = {};
428430
forEach(url.split(/\W/), function(param) {
@@ -435,6 +437,10 @@ angular.module('ngResource', ['ng']).
435437
}
436438
});
437439
url = url.replace(/\\:/g, ':');
440+
url = url.replace(PROTOCOL_AND_DOMAIN_REGEX, function(match) {
441+
protocolAndDomain = match;
442+
return '';
443+
});
438444

439445
params = params || {};
440446
forEach(self.urlParams, function(_, urlParam) {
@@ -465,7 +471,7 @@ angular.module('ngResource', ['ng']).
465471
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
466472
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
467473
// replace escaped `/\.` with `/.`
468-
config.url = url.replace(/\/\\\./, '/.');
474+
config.url = protocolAndDomain + url.replace(/\/\\\./, '/.');
469475

470476

471477
// set params - delegate param encoding to $http

test/ngResource/resourceSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ describe("resource", function() {
297297
R.get({a: 'foo'});
298298
});
299299

300+
it('should support IPv6 URLs', function() {
301+
var R = $resource('http://[2620:0:861:ed1a::1]/:ed1a/', {}, {}, {stripTrailingSlashes: false});
302+
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/foo/').respond({});
303+
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/').respond({});
304+
R.get({ed1a: 'foo'});
305+
R.get({});
306+
});
307+
300308
it('should support overriding provider default trailing-slash stripping configuration', function() {
301309
// Set the new behavior for all new resources created by overriding the
302310
// provider configuration

0 commit comments

Comments
 (0)