diff --git a/lib/manager.js b/lib/manager.js index ea18a4dbe..fd3beca8e 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -3,7 +3,6 @@ * Module dependencies. */ -var url = require('./url'); var eio = require('engine.io-client'); var Socket = require('./socket'); var Emitter = require('component-emitter'); diff --git a/lib/url.js b/lib/url.js index 6000b6f60..dd3982bd1 100644 --- a/lib/url.js +++ b/lib/url.js @@ -64,10 +64,13 @@ function url(uri, loc){ obj.path = obj.path || '/'; + var ipv6 = obj.host.indexOf(':') !== -1; + var host = ipv6 ? '[' + obj.host + ']' : obj.host; + // define unique id - obj.id = obj.protocol + '://' + obj.host + ':' + obj.port; + obj.id = obj.protocol + '://' + host + ':' + obj.port; // define href - obj.href = obj.protocol + '://' + obj.host + (loc && loc.port == obj.port ? '' : (':' + obj.port)); + obj.href = obj.protocol + '://' + host + (loc && loc.port == obj.port ? '' : (':' + obj.port)); return obj; } diff --git a/package.json b/package.json index 23fe9b73a..a2ed0f2ae 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "socket.io-parser": "2.2.5", "has-binary": "0.1.7", "indexof": "0.0.1", - "parseuri": "0.0.2", + "parseuri": "0.0.4", "to-array": "0.1.3", "backo2": "1.0.2" }, diff --git a/test/url.js b/test/url.js index 21855cd6e..cf27ccb86 100644 --- a/test/url.js +++ b/test/url.js @@ -61,4 +61,24 @@ describe('url', function(){ expect(url('http://google.com/').path).to.be('/'); }); + it('works with ipv6', function(){ + var parsed = url('http://[::1]'); + expect(parsed.protocol).to.be('http'); + expect(parsed.host).to.be('::1'); + expect(parsed.port).to.be('80'); + expect(parsed.id).to.be('http://[::1]:80'); + }); + + it('works with ipv6 location', function(){ + loc.protocol = 'http:'; + loc.hostname = '[::1]'; + loc.port = ''; + loc.host = loc.hostname + ':' + loc.port; + + var parsed = url(undefined, loc); + expect(parsed.protocol).to.be('http'); + expect(parsed.host).to.be('::1'); + expect(parsed.port).to.be('80'); + expect(parsed.id).to.be('http://[::1]:80'); + }); });