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

fix(ngResources): support IPv6 URLs #12532

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ function shallowClearAndCopy(src, dst) {
*/
angular.module('ngResource', ['ng']).
provider('$resource', function() {
var PROTOCOL_AND_DOMAIN_REGEX = /^http(?:s)?:\/\/[^\/]*/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not (?:s)? --> s? ?

var provider = this;

this.defaults = {
Expand Down Expand Up @@ -422,7 +423,8 @@ angular.module('ngResource', ['ng']).
var self = this,
url = actionUrl || self.template,
val,
encodedVal;
encodedVal,
protocolAndDomain = '';

var urlParams = self.urlParams = {};
forEach(url.split(/\W/), function(param) {
Expand All @@ -435,6 +437,10 @@ angular.module('ngResource', ['ng']).
}
});
url = url.replace(/\\:/g, ':');
url = url.replace(PROTOCOL_AND_DOMAIN_REGEX, function(match) {
protocolAndDomain = match;
return '';
});

params = params || {};
forEach(self.urlParams, function(_, urlParam) {
Expand Down Expand Up @@ -465,7 +471,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 = url.replace(/\/\\\./, '/.');
config.url = protocolAndDomain + url.replace(/\/\\\./, '/.');


// set params - delegate param encoding to $http
Expand Down
8 changes: 8 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ describe("resource", function() {
R.get({a: 'foo'});
});

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({});
});

it('should support overriding provider default trailing-slash stripping configuration', function() {
// Set the new behavior for all new resources created by overriding the
// provider configuration
Expand Down