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

Commit b617b25

Browse files
committed
fixup! fix($resource): allow params in hostname (except for IPv6 addresses)
1 parent 45f0939 commit b617b25

File tree

1 file changed

+26
-42
lines changed

1 file changed

+26
-42
lines changed

test/ngResource/resourceSpec.js

+26-42
Original file line numberDiff line numberDiff line change
@@ -321,51 +321,35 @@ describe('basic usage', function() {
321321
});
322322

323323
it('should support IPv6 URLs', function() {
324-
var keepSlashes = {stripTrailingSlashes: false};
325-
326-
var R1 = $resource('http://[2620:0:861:ed1a::1]', null, null, keepSlashes);
327-
var R2 = $resource('http://[2620:0:861:ed1a::1]/', null, null, keepSlashes);
328-
var R3 = $resource('http://[2620:0:861:ed1a::1]/:ed1a', null, null, keepSlashes);
329-
var R4 = $resource('http://[2620:0:861:ed1a::1]/:ed1a/', null, null, keepSlashes);
330-
331-
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]').respond(null); // R1
332-
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/').respond(null); // R2
333-
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/foo').respond(null); // R3
334-
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/').respond(null); // R3
335-
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/foo/').respond(null); // R4
336-
$httpBackend.expect('GET', 'http://[2620:0:861:ed1a::1]/').respond(null); // R4
337-
338-
R1.get({ed1a: 'foo'});
339-
R2.get({ed1a: 'foo'});
340-
R3.get({ed1a: 'foo'});
341-
R3.get({});
342-
R4.get({ed1a: 'foo'});
343-
R4.get({});
324+
test('http://[2620:0:861:ed1a::1]', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]');
325+
test('http://[2620:0:861:ed1a::1]/', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/');
326+
test('http://[2620:0:861:ed1a::1]/:ed1a', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/foo');
327+
test('http://[2620:0:861:ed1a::1]/:ed1a', {}, 'http://[2620:0:861:ed1a::1]/');
328+
test('http://[2620:0:861:ed1a::1]/:ed1a/', {ed1a: 'foo'}, 'http://[2620:0:861:ed1a::1]/foo/');
329+
test('http://[2620:0:861:ed1a::1]/:ed1a/', {}, 'http://[2620:0:861:ed1a::1]/');
330+
331+
// Helpers
332+
function test(templateUrl, params, actualUrl) {
333+
var R = $resource(templateUrl, null, null, {stripTrailingSlashes: false});
334+
$httpBackend.expect('GET', actualUrl).respond(null);
335+
R.get(params);
336+
}
344337
});
345338

346339
it('should support params in the `hostname` part of the URL', function() {
347-
var keepSlashes = {stripTrailingSlashes: false};
348-
349-
var R1 = $resource('http://:hostname', null, null, keepSlashes);
350-
var R2 = $resource('http://:hostname/', null, null, keepSlashes);
351-
var R3 = $resource('http://:l2Domain.:l1Domain', null, null, keepSlashes);
352-
var R4 = $resource('http://:l2Domain.:l1Domain/', null, null, keepSlashes);
353-
var R5 = $resource('http://127.0.0.:octet', null, null, keepSlashes);
354-
var R6 = $resource('http://127.0.0.:octet/', null, null, keepSlashes);
355-
356-
$httpBackend.expect('GET', 'http://foo.com').respond(null); // R1
357-
$httpBackend.expect('GET', 'http://foo.com/').respond(null); // R2
358-
$httpBackend.expect('GET', 'http://bar.com').respond(null); // R3
359-
$httpBackend.expect('GET', 'http://bar.com/').respond(null); // R4
360-
$httpBackend.expect('GET', 'http://127.0.0.42').respond(null); // R5
361-
$httpBackend.expect('GET', 'http://127.0.0.42/').respond(null); // R6
362-
363-
R1.get({hostname: 'foo.com'});
364-
R2.get({hostname: 'foo.com'});
365-
R3.get({l1Domain: 'com', l2Domain: 'bar'});
366-
R4.get({l1Domain: 'com', l2Domain: 'bar'});
367-
R5.get({octet: 42});
368-
R6.get({octet: 42});
340+
test('http://:hostname', {hostname: 'foo.com'}, 'http://foo.com');
341+
test('http://:hostname/', {hostname: 'foo.com'}, 'http://foo.com/');
342+
test('http://:l2Domain.:l1Domain', {l1Domain: 'com', l2Domain: 'bar'}, 'http://bar.com');
343+
test('http://:l2Domain.:l1Domain/', {l1Domain: 'com', l2Domain: 'bar'}, 'http://bar.com/');
344+
test('http://127.0.0.:octet', {octet: 42}, 'http://127.0.0.42');
345+
test('http://127.0.0.:octet/', {octet: 42}, 'http://127.0.0.42/');
346+
347+
// Helpers
348+
function test(templateUrl, params, actualUrl) {
349+
var R = $resource(templateUrl, null, null, {stripTrailingSlashes: false});
350+
$httpBackend.expect('GET', actualUrl).respond(null);
351+
R.get(params);
352+
}
369353
});
370354

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

0 commit comments

Comments
 (0)