Skip to content

Commit 65e21d0

Browse files
committed
chore: Add some comments to correctProtocol
1 parent 7b273bb commit 65e21d0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/parse-url.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ const correctProtocol = (arg, protocols) => {
2121
return arg
2222
}
2323

24-
const doubleSlash = arg.indexOf('//')
25-
if (doubleSlash === firstColon + 1) {
24+
if (arg.substr(firstColon, 3) === '://') {
25+
// If arg is given as <foo>://<bar>, then this is already a valid URL.
2626
return arg
2727
}
2828

2929
const firstAt = arg.indexOf('@')
3030
if (firstAt > -1) {
3131
if (firstAt > firstColon) {
32+
// URL has the form of <foo>:<bar>@<baz>. Assume this is a git+ssh URL.
3233
return `git+ssh://${arg}`
3334
} else {
35+
// URL has the form '[email protected]:npm/hosted-git-info.git'.
3436
return arg
3537
}
3638
}
3739

40+
// Correct <foo>:<bar> to <foo>://<bar>
3841
return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}`
3942
}
4043

0 commit comments

Comments
 (0)