diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 8ae971ed6..96ba6dc44 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -120,8 +120,15 @@ export default function isURL(url, options) { ? after_colon : after_colon.substring(0, first_slash_position); const at_position = before_slash.indexOf('@'); + const is_host_with_port = /^[0-9]+$/.test(before_slash); - if (at_position !== -1) { + if (is_host_with_port) { + if (options.require_protocol) { + return false; + } + + // Don't consume the colon; let host/port parsing handle it later. + } else if (at_position !== -1) { const before_at = before_slash.substring(0, at_position); const valid_auth_regex = /^[a-zA-Z0-9\-_.%:]*$/; const is_valid_auth = valid_auth_regex.test(before_at); 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',