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

Commit 02f045b

Browse files
committed
revert: fix($resource): allow params in hostname (except for IPv6 addresses)
This reverts commit 7f45b5f.
1 parent 71083a4 commit 02f045b

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

src/ngResource/resource.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ function shallowClearAndCopy(src, dst) {
427427
*/
428428
angular.module('ngResource', ['ng']).
429429
provider('$resource', function ResourceProvider() {
430-
var PROTOCOL_AND_IPV6_REGEX = /^https?:\/\/\[[^\]]*][^/]*/;
430+
var PROTOCOL_AND_DOMAIN_REGEX = /^https?:\/\/[^/]*/;
431431

432432
var provider = this;
433433

@@ -575,7 +575,7 @@ angular.module('ngResource', ['ng']).
575575
url = actionUrl || self.template,
576576
val,
577577
encodedVal,
578-
protocolAndIpv6 = '';
578+
protocolAndDomain = '';
579579

580580
var urlParams = self.urlParams = {};
581581
forEach(url.split(/\W/), function(param) {
@@ -590,8 +590,8 @@ angular.module('ngResource', ['ng']).
590590
}
591591
});
592592
url = url.replace(/\\:/g, ':');
593-
url = url.replace(PROTOCOL_AND_IPV6_REGEX, function(match) {
594-
protocolAndIpv6 = match;
593+
url = url.replace(PROTOCOL_AND_DOMAIN_REGEX, function(match) {
594+
protocolAndDomain = match;
595595
return '';
596596
});
597597

@@ -628,7 +628,7 @@ angular.module('ngResource', ['ng']).
628628
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
629629
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
630630
// replace escaped `/\.` with `/.`
631-
config.url = protocolAndIpv6 + url.replace(/\/\\\./, '/.');
631+
config.url = protocolAndDomain + url.replace(/\/\\\./, '/.');
632632

633633

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

test/ngResource/resourceSpec.js

+5-29
Original file line numberDiff line numberDiff line change
@@ -300,35 +300,11 @@ describe('basic usage', function() {
300300
});
301301

302302
it('should support IPv6 URLs', function() {
303-
test('http://[2620:0:861:ed1a::1]', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]');
304-
test('http://[2620:0:861:ed1a::1]/', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/');
305-
test('http://[2620:0:861:ed1a::1]/:ed1a', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/foo');
306-
test('http://[2620:0:861:ed1a::1]/:ed1a', {}, 'http://[2620:0:861:ed1a::1]/');
307-
test('http://[2620:0:861:ed1a::1]/:ed1a/', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/foo/');
308-
test('http://[2620:0:861:ed1a::1]/:ed1a/', {}, 'http://[2620:0:861:ed1a::1]/');
309-
310-
// Helpers
311-
function test(templateUrl, params, actualUrl) {
312-
var R = $resource(templateUrl, null, null, {stripTrailingSlashes: false});
313-
$httpBackend.expect('GET', actualUrl).respond(null);
314-
R.get(params);
315-
}
316-
});
317-
318-
it('should support params in the `hostname` part of the URL', function() {
319-
test('http://:hostname', {hostname: 'foo.com'}, 'http://foo.com');
320-
test('http://:hostname/', {hostname: 'foo.com'}, 'http://foo.com/');
321-
test('http://:l2Domain.:l1Domain', {l1Domain: 'com', l2Domain: 'bar'}, 'http://bar.com');
322-
test('http://:l2Domain.:l1Domain/', {l1Domain: 'com', l2Domain: 'bar'}, 'http://bar.com/');
323-
test('http://127.0.0.:octet', {octet: 42}, 'http://127.0.0.42');
324-
test('http://127.0.0.:octet/', {octet: 42}, 'http://127.0.0.42/');
325-
326-
// Helpers
327-
function test(templateUrl, params, actualUrl) {
328-
var R = $resource(templateUrl, null, null, {stripTrailingSlashes: false});
329-
$httpBackend.expect('GET', actualUrl).respond(null);
330-
R.get(params);
331-
}
303+
var R = $resource('http://[2620:0:861:ed1a::1]/:ed1a/', {}, {}, {stripTrailingSlashes: false});
304+
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/foo/').respond({});
305+
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/').respond({});
306+
R.get({ed1a: 'foo'});
307+
R.get({});
332308
});
333309

334310
it('should support overriding provider default trailing-slash stripping configuration', function() {

0 commit comments

Comments
 (0)