-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Do not pass scp-style URLs to the WhatWG url.URL
Fix #60 (for the legacy branch)
- Loading branch information
Showing
3 changed files
with
19 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,9 +109,22 @@ function parseGitUrl (giturl) { | |
if (!matched) { | ||
var legacy = url.parse(giturl) | ||
if (legacy.auth) { | ||
var whatwg = new url.URL(giturl) | ||
legacy.auth = whatwg.username || '' | ||
if (whatwg.password) legacy.auth += ':' + whatwg.password | ||
// git urls can be in the form of scp-style/ssh-connect strings, like | ||
// git+ssh://[email protected]:some/path, which the legacy url parser | ||
// supports, but WhatWG url.URL class does not. However, the legacy | ||
// parser de-urlencodes the username and password, so something like | ||
// https://user%3An%40me:p%40ss%[email protected]/ becomes | ||
// https://user:n@me:p@ss:[email protected]/ which is all kinds of wrong. | ||
// Pull off just the auth and host, so we dont' get the confusing | ||
// scp-style URL, then pass that to the WhatWG parser to get the | ||
// auth properly escaped. | ||
const authmatch = giturl.match(/[^@]+@[^:/]+/) | ||
/* istanbul ignore else - this should be impossible */ | ||
if (authmatch) { | ||
var whatwg = new url.URL(authmatch[0]) | ||
legacy.auth = whatwg.username || '' | ||
if (whatwg.password) legacy.auth += ':' + whatwg.password | ||
} | ||
} | ||
return legacy | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ test('basic', function (t) { | |
t.is(HostedGit.fromUrl('github.com/abc/def/'), undefined, 'forgot the protocol') | ||
t.is(HostedGit.fromUrl('completely-invalid'), undefined, 'not a url is not hosted') | ||
|
||
t.is(HostedGit.fromUrl('git+ssh://[email protected]:RND/electron-tools/some-tool#2.0.1'), undefined, 'properly ignores non-hosted scp style urls') | ||
|
||
t.is(HostedGit.fromUrl('http://github.com/foo/bar').toString(), 'git+ssh://[email protected]/foo/bar.git', 'github http protocol use git+ssh urls') | ||
t.end() | ||
}) |