Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle protocols that seperate the host from path with colon #3471

Closed
wants to merge 3 commits into from

6 participants

@pksunkara

Fixes #1627. Added tests too.

@bnoordhuis bnoordhuis commented on the diff
lib/url.js
((5 lines not shown))
'http:': true,
'https:': true,
'ftp:': true,
'gopher:': true,
- 'file:': true
+ 'file:': true,
+ 'ssh:': true

Unnecessary change, please undo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bnoordhuis

@isaacs You should probably review this. I don't know if this is what you had in mind when you filed #1627.

The problem I see with it is that it's a hard-coded protocol check. It breaks down when people use mashup URLs like 'git+ssh://example.com:path/to/foo'.

@pksunkara

@bnoordhuis @isaacs and me talked about it in IRC and he gave me some feedback. I am going to modify this soon.

@isaacs

@bnoordhuis Yes, I want to +1 this before landing. Thanks.

@pksunkara Feel free to continue to discuss in IRC and elsewhere :)

@trevnorris
Owner

@pksunkara, I'd hate to see your work for naught. Thinking of providing an update? =)

@Nodejs-Jenkins
Collaborator

Can one of the admins verify this patch?

@hackedy

@pksunkara has deleted their fork so this particular pull can get closed. I am going to open a PR in a minute with this fix, though

@isaacs

@hackedy If you do, can you please reference #3471 in the comments, so that we have continuity? Thanks.

@isaacs isaacs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 44 additions and 15 deletions.
  1. +20 −2 lib/url.js
  2. +24 −13 test/simple/test-url.js
View
22 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

Unnecessary change, please undo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
},
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;
View
37 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/',
@@ -505,24 +517,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
Something went wrong with that request. Please try again.