From b717bd96b10082654c25e3cc250193977184cb28 Mon Sep 17 00:00:00 2001 From: rawalcher Date: Mon, 27 Jan 2025 12:05:35 +0100 Subject: [PATCH] modified regex - it matched "www.google" which shouldnt be possible --- frontend/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/index.js b/frontend/index.js index 3c312be..da7e0ed 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -2,7 +2,8 @@ document.getElementById("urlInput").addEventListener("input", function() { const urlInput = document.getElementById("urlInput"); const shortenButton = document.getElementById("shortenButton"); - const urlPattern = /^(https?:\/\/)?([\w\d-]+\.)+[a-z]{2,6}(\/[\w\d-]*)*\/?$/i; + const urlPattern = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/i + const isValid = urlPattern.test(urlInput.value); if (isValid) {