From 7b273bb271c75e48c5dc69b85ce59db8dd4843a2 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Tue, 7 Oct 2025 15:02:30 -0700 Subject: [PATCH 1/2] fix: correctProtocol misparsing protocol --- lib/parse-url.js | 10 +++++----- test/parse-url.js | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/parse-url.js b/lib/parse-url.js index 7d5489c0..e088c466 100644 --- a/lib/parse-url.js +++ b/lib/parse-url.js @@ -21,6 +21,11 @@ const correctProtocol = (arg, protocols) => { return arg } + const doubleSlash = arg.indexOf('//') + if (doubleSlash === firstColon + 1) { + return arg + } + const firstAt = arg.indexOf('@') if (firstAt > -1) { if (firstAt > firstColon) { @@ -30,11 +35,6 @@ const correctProtocol = (arg, protocols) => { } } - const doubleSlash = arg.indexOf('//') - if (doubleSlash === firstColon + 1) { - return arg - } - return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}` } diff --git a/test/parse-url.js b/test/parse-url.js index 54e7d169..70f04b10 100644 --- a/test/parse-url.js +++ b/test/parse-url.js @@ -15,3 +15,10 @@ t.test('can parse file urls', async t => { t.ok(parseUrl(u)) t.ok(HostedGit.parseUrl(u)) }) + +t.test('can parse custom urls', async t => { + const u = 'foobar://user:host@path' + t.ok(parseUrl(u, {})) + t.equal(parseUrl(u, {}).protocol, 'foobar:') + t.ok(HostedGit.parseUrl(u)) +}) From 65e21d0d50f955f0dc8f4c7dfe178180dc98c3b2 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Wed, 8 Oct 2025 08:33:47 -0700 Subject: [PATCH 2/2] chore: Add some comments to correctProtocol --- lib/parse-url.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/parse-url.js b/lib/parse-url.js index e088c466..bfd54b91 100644 --- a/lib/parse-url.js +++ b/lib/parse-url.js @@ -21,20 +21,23 @@ const correctProtocol = (arg, protocols) => { return arg } - const doubleSlash = arg.indexOf('//') - if (doubleSlash === firstColon + 1) { + if (arg.substr(firstColon, 3) === '://') { + // If arg is given as ://, then this is already a valid URL. return arg } const firstAt = arg.indexOf('@') if (firstAt > -1) { if (firstAt > firstColon) { + // URL has the form of :@. Assume this is a git+ssh URL. return `git+ssh://${arg}` } else { + // URL has the form 'git@github.com:npm/hosted-git-info.git'. return arg } } + // Correct : to :// return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}` }