From e5805e4195419d7c72f2c8be26818ac689dbaae1 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Thu, 23 Mar 2023 10:03:14 +0100 Subject: [PATCH] fix: align FormValidation.js customization with Volto pr #4601 (fix isValidURL regexp) --- .../volto/helpers/FormValidation/FormValidation.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/customizations/volto/helpers/FormValidation/FormValidation.js b/src/customizations/volto/helpers/FormValidation/FormValidation.js index 9374508de..c7985aec4 100644 --- a/src/customizations/volto/helpers/FormValidation/FormValidation.js +++ b/src/customizations/volto/helpers/FormValidation/FormValidation.js @@ -73,8 +73,16 @@ const widgetValidation = { }, url: { isValidURL: (urlValue, urlObj, intlFunc) => { - const urlRegex = - /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([_.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|^((http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm; + var urlRegex = new RegExp( + '^(https?:\\/\\/)?' + // validate protocol + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name + '((\\d{1,3}\\.){3}\\d{1,3}))|' + // validate OR ip (v4) address + '(localhost)' + // validate OR localhost address + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path + '(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string + '(\\#[-a-z\\d_]*)?$', // validate fragment locator + 'i', + ); const isValid = urlRegex.test(urlValue); return !isValid ? intlFunc(messages.isValidURL) : null; },