From 3e32c6605d074cc43428249c91bb4afa45f65330 Mon Sep 17 00:00:00 2001 From: "codefix-patchflow[bot]" <292349666+codefix-patchflow[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 11:32:15 +0000 Subject: [PATCH] fix: preserve no-protocol host:port URL parsing --- src/lib/isURL.js | 5 +++-- test/validators.test.js | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 8ae971ed6..560f9b041 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -120,6 +120,7 @@ export default function isURL(url, options) { ? after_colon : after_colon.substring(0, first_slash_position); const at_position = before_slash.indexOf('@'); + const looks_like_port = /^[0-9]+$/.test(before_slash); if (at_position !== -1) { const before_at = before_slash.substring(0, at_position); @@ -141,8 +142,8 @@ export default function isURL(url, options) { return false; } } - } else { - // No @ symbol, this is definitely a protocol + } else if (options.require_protocol || !looks_like_port) { + // No @ symbol and not an allowed host:port URL, so treat it as a protocol. url = cleanUpProtocol(potential_protocol); if (url === false) { 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',