From f309967214aad0403e8b7a72392c86ec2abb932a Mon Sep 17 00:00:00 2001 From: Wessel Tip Date: Thu, 8 Feb 2024 13:25:46 +0100 Subject: [PATCH] fix(regex): Allow all TLDs Fix for #627 - Updates all URL regexes to allow up to 63 octets for TLDs, which is the RFC 1034 standard (https://www.rfc-editor.org/rfc/rfc1034) --- .../modals/main/settings/sections/background/Custom.jsx | 2 +- src/modules/helpers/marketplace.js | 2 +- src/modules/helpers/settings/modals.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/modals/main/settings/sections/background/Custom.jsx b/src/components/modals/main/settings/sections/background/Custom.jsx index 8b7135d3..69aa6ef4 100644 --- a/src/components/modals/main/settings/sections/background/Custom.jsx +++ b/src/components/modals/main/settings/sections/background/Custom.jsx @@ -125,7 +125,7 @@ export default class CustomSettings extends PureComponent { // regex: https://ihateregex.io/expr/url/ // eslint-disable-next-line no-useless-escape const urlRegex = - /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_.~#?&=]*)/; + /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._~#=]{1,256}\.[a-zA-Z0-9()]{1,63}\b([-a-zA-Z0-9()!@:%_.~#?&=]*)/; if (urlRegex.test(e) === false) { return this.setState({ urlError: variables.getMessage('widgets.quicklinks.url_error'), diff --git a/src/modules/helpers/marketplace.js b/src/modules/helpers/marketplace.js index 74bd4b70..50233f1a 100644 --- a/src/modules/helpers/marketplace.js +++ b/src/modules/helpers/marketplace.js @@ -12,7 +12,7 @@ function sleep(ms) { // based on https://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links export function urlParser(input) { const urlPattern = - /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_+.~#?&//=]*)/; + /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,63}\b([-a-zA-Z0-9()!@:%_+.~#?&//=]*)/; return input.replace(urlPattern, '
$&'); } diff --git a/src/modules/helpers/settings/modals.js b/src/modules/helpers/settings/modals.js index c2988b0c..24aa52a0 100644 --- a/src/modules/helpers/settings/modals.js +++ b/src/modules/helpers/settings/modals.js @@ -144,7 +144,7 @@ export function isValidUrl(url) { // regex: https://ihateregex.io/expr/url/ // eslint-disable-next-line no-useless-escape const urlRegex = - /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_.~#?&=]*)/; + /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._~#=]{1,256}\.[a-zA-Z0-9()]{1,63}\b([-a-zA-Z0-9()!@:%_.~#?&=]*)/; return urlRegex.test(url); }