From e14c24280faef74df72e45d718d4fd05e9fc610b Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Mon, 18 Jun 2012 03:25:08 +0530 Subject: [PATCH 1/3] test: Fix loss of uniformity in simple/test-url --- test/simple/test-url.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/test/simple/test-url.js b/test/simple/test-url.js index ff4a8449eb0..608b5bd8b79 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -505,24 +505,23 @@ var parseTests = { }, 'http://bucket_name.s3.amazonaws.com/image.jpg': { - protocol: 'http:', + 'protocol': 'http:', 'slashes': true, - slashes: true, - host: 'bucket_name.s3.amazonaws.com', - hostname: 'bucket_name.s3.amazonaws.com', - pathname: '/image.jpg', - href: 'http://bucket_name.s3.amazonaws.com/image.jpg', + 'host': 'bucket_name.s3.amazonaws.com', + 'hostname': 'bucket_name.s3.amazonaws.com', + 'pathname': '/image.jpg', + 'href': 'http://bucket_name.s3.amazonaws.com/image.jpg', 'path': '/image.jpg' }, 'git+http://github.com/joyent/node.git': { - protocol: 'git+http:', - slashes: true, - host: 'github.com', - hostname: 'github.com', - pathname: '/joyent/node.git', - path: '/joyent/node.git', - href: 'git+http://github.com/joyent/node.git' + 'protocol': 'git+http:', + 'slashes': true, + 'host': 'github.com', + 'hostname': 'github.com', + 'pathname': '/joyent/node.git', + 'path': '/joyent/node.git', + 'href': 'git+http://github.com/joyent/node.git' }, //if local1@domain1 is uses as a relative URL it may From 74dfb14219f5cbf31da936218717f6007616d4f3 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Mon, 18 Jun 2012 03:10:43 +0530 Subject: [PATCH 2/3] test: Added a test for #1627 to simple/test-url --- test/simple/test-url.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/simple/test-url.js b/test/simple/test-url.js index 608b5bd8b79..08ef0f3d108 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -430,6 +430,18 @@ var parseTests = { 'path': '/bar' }, + // protocols that seperate the host from path with ':' + 'ssh://user@foo.com:folder': { + 'href': 'ssh://user@foo.com:folder', + 'host': 'foo.com', + 'auth': 'user', + 'hostname': 'foo.com', + 'protocol': 'ssh:', + 'pathname': 'folder', + 'path': 'folder', + 'slashes': true + }, + // IDNA tests 'http://www.日本語.com/' : { 'href': 'http://www.xn--wgv71a119e.com/', From 1bfa6f4c651804bf79927761e914fe365bcd0ed9 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Mon, 18 Jun 2012 04:08:06 +0530 Subject: [PATCH 3/3] url: Handle protocols that seperate the host from path with colon, Fixes #1627 --- lib/url.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/url.js b/lib/url.js index 50eb8b20f66..cc98e5a70e3 100644 --- a/lib/url.js +++ b/lib/url.js @@ -74,6 +74,11 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i, 'gopher:': true, 'file:': true }, + // protocols that seperat host from path with colon. + colonProtocol = { + 'ssh': true, + 'ssh:': true + }, // protocols that always contain a // bit. slashedProtocol = { 'http': true, @@ -81,11 +86,13 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i, 'ftp': true, 'gopher': true, 'file': true, + 'ssh': true, 'http:': true, 'https:': true, 'ftp:': true, 'gopher:': true, - 'file:': true + 'file:': true, + 'ssh:': true }, querystring = require('querystring'); @@ -300,6 +307,12 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { out.pathname = '/'; } + // protocols that seperate host from path with ':' + if (colonProtocol[proto] && + out.pathname && out.pathname.slice(0, 2) == '/:') { + out.pathname = out.pathname.substr(2); + } + //to support http.request if (out.pathname || out.search) { out.path = (out.pathname ? out.pathname : '') + @@ -357,11 +370,16 @@ function urlFormat(obj) { if (obj.slashes || (!protocol || slashedProtocol[protocol]) && host !== false) { host = '//' + (host || ''); - if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; + if (pathname && pathname.charAt(0) !== '/' && + !colonProtocol[protocol]) { + pathname = '/' + pathname; + } } else if (!host) { host = ''; } + if (colonProtocol[protocol] && pathname) pathname = ':' + pathname; + if (hash && hash.charAt(0) !== '#') hash = '#' + hash; if (search && search.charAt(0) !== '?') search = '?' + search;