Skip to content

Commit a1e54d6

Browse files
evanlucasbnoordhuis
authored andcommitted
url: fix parsing of ssh urls
Fix regression introduced in 6120472 that broke parsing of some ssh: urls. An example url is ssh://[email protected]:npm/npm.git PR-URL: #299 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 70c2501 commit a1e54d6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/url.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
7272
nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
7373
hostEndingChars = ['/', '?', '#'],
7474
hostnameMaxLen = 255,
75-
hostnamePatternString = '[^' + nonHostChars.join('') + ']{0,63}',
76-
hostnamePartPattern = new RegExp('^' + hostnamePatternString + '$'),
77-
hostnamePartStart = new RegExp('^(' + hostnamePatternString + ')(.*)$'),
75+
hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
76+
hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
7877
// protocols that can allow "unsafe" and "unwise" chars.
7978
unsafeProtocol = {
8079
'javascript': true,

test/parallel/test-url.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,22 @@ var parseTests = {
857857
pathname: '%0D%0Ad/e',
858858
path: '%0D%0Ad/e?f',
859859
href: 'http://a%0D%22%20%09%0A%3C\'b:b@c/%0D%0Ad/e?f'
860+
},
861+
862+
// git urls used by npm
863+
'git+ssh://[email protected]:npm/npm': {
864+
protocol: 'git+ssh:',
865+
slashes: true,
866+
auth: 'git',
867+
host: 'github.com',
868+
port: null,
869+
hostname: 'github.com',
870+
hash: null,
871+
search: null,
872+
query: null,
873+
pathname: '/:npm/npm',
874+
path: '/:npm/npm',
875+
href: 'git+ssh://[email protected]/:npm/npm'
860876
}
861877

862878
};

0 commit comments

Comments
 (0)