From b49b22ed68d3ccb376e037fc0a9da2fcd3b16103 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Tue, 22 Oct 2024 13:11:23 -0700 Subject: [PATCH] #117 fix regex on clickable url match --- .../conversation/topicItem/useTopicItem.hook.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js b/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js index 240da097b..7a958d0be 100644 --- a/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js +++ b/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js @@ -279,20 +279,14 @@ export function useTopicItem(item, hosting, remove, contentKey) { }; const clickableText = (text) => { - const urlPatternn = new RegExp('^(https?:\\/\\/)?'+ // protocol - '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name - '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address - '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path - '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string - '(\\#[-a-z\\d_]*)?$','i'); // fragment locator - + const urlPattern = new RegExp('(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)'); const hostPattern = new RegExp('^https?:\\/\\/', 'i'); let clickable = []; let group = ''; const words = text == null ? [''] : text.split(' '); words.forEach((word, index) => { - if (!!urlPatternn.test(word)) { + if (!!urlPattern.test(word)) { clickable.push({ group }); group = ''; const url = !!hostPattern.test(word) ? word : `https://${word}`;