Skip to content

Commit

Permalink
Fix handling of protocol-less URLs with a port
Browse files Browse the repository at this point in the history
Fixes #187
Closes #186
  • Loading branch information
sindresorhus committed Mar 10, 2024
1 parent 12e3b1b commit dec5dc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -13,7 +13,10 @@ const supportedProtocols = new Set([
const hasCustomProtocol = urlString => {
try {
const {protocol} = new URL(urlString);
return protocol.endsWith(':') && !supportedProtocols.has(protocol);

return protocol.endsWith(':')
&& !protocol.includes('.')
&& !supportedProtocols.has(protocol);
} catch {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions test.js
Expand Up @@ -39,6 +39,7 @@ test('main', t => {
// t.is(normalizeUrl('sindre://www.sorhus.com/'), 'sindre://sorhus.com');
// t.is(normalizeUrl('sindre://www.sorhus.com/foo/bar'), 'sindre://sorhus.com/foo/bar');
t.is(normalizeUrl('https://i.vimeocdn.com/filter/overlay?src0=https://i.vimeocdn.com/video/598160082_1280x720.jpg&src1=https://f.vimeocdn.com/images_v6/share/play_icon_overlay.png'), 'https://i.vimeocdn.com/filter/overlay?src0=https://i.vimeocdn.com/video/598160082_1280x720.jpg&src1=https://f.vimeocdn.com/images_v6/share/play_icon_overlay.png');
t.is(normalizeUrl('sindresorhus.com:123'), 'http://sindresorhus.com:123');
});

test('defaultProtocol option', t => {
Expand Down

0 comments on commit dec5dc6

Please sign in to comment.