From f2dc4495472071d3ed9a5637f35660226c8e44c6 Mon Sep 17 00:00:00 2001 From: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com> Date: Sat, 25 Apr 2026 19:27:58 +0300 Subject: [PATCH] fix(parseProtocol): fix regex to require colon in protocol separator (#10729) The regex used `(:?\/\/|:)` where `:?` was intended to be a non-capturing group `(?:` but instead made the colon an optional literal character. This caused URLs without a colon separator like `http//example.com` to incorrectly match and return `http` as the protocol. Fix the regex to `:(?:\/\/)?` which requires the colon and optionally matches `//`, correctly rejecting malformed URLs. Signed-off-by: Nikita Skovoroda Co-authored-by: Claude Opus 4.6 Co-authored-by: Nikita Skovoroda Co-authored-by: Jay --- lib/helpers/parseProtocol.js | 2 +- tests/unit/parseProtocol.test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/helpers/parseProtocol.js b/lib/helpers/parseProtocol.js index 1ad6658c..05a2d6d2 100644 --- a/lib/helpers/parseProtocol.js +++ b/lib/helpers/parseProtocol.js @@ -1,6 +1,6 @@ 'use strict'; export default function parseProtocol(url) { - const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url); + const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url); return (match && match[1]) || ''; } diff --git a/tests/unit/parseProtocol.test.js b/tests/unit/parseProtocol.test.js index 6a295f36..ec546efe 100644 --- a/tests/unit/parseProtocol.test.js +++ b/tests/unit/parseProtocol.test.js @@ -25,4 +25,8 @@ describe('helpers::parseProtocol', () => { } ); }); + + it('should not match URLs without a colon separator', () => { + assert.strictEqual(parseProtocol('http//example.com'), ''); + }); });