Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export default function isURL(url, options) {
// However, we need to be careful not to confuse authentication credentials (user:password@host)
// with protocols. A colon before an @ symbol might be part of auth, not a protocol separator.
const protocol_match = url.match(/^([a-z][a-z0-9+\-.]*):/i);
// Keep protocol-less hostname:port URLs on the host parsing path.
const host_port_match = protocol_match
&& /^[0-9]+(?:\/|$)/.test(url.substring(protocol_match[0].length));
let had_explicit_protocol = false;

const cleanUpProtocol = (potential_protocol) => {
Expand All @@ -103,7 +106,7 @@ export default function isURL(url, options) {
return url.substring(protocol_match[0].length);
};

if (protocol_match) {
if (protocol_match && !host_port_match) {
const potential_protocol = protocol_match[1];
const after_colon = url.substring(protocol_match[0].length);

Expand Down
1 change: 1 addition & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ describe('Validators', () => {
'localhost',
'localhost:3000',
'service-name:8080',
'my-3272-service:9000',
'https://localhost',
'http://localhost:3000',
'http://service-name:8080',
Expand Down
Loading