diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 8ae971ed6..d03603e56 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -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) => { @@ -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); diff --git a/test/validators.test.js b/test/validators.test.js index 5196c6fe9..9db1f1745 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -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',