Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
Make sure we do only one replacement, not one over another for messages.
damenchocd77a9176c62
diff --git a/react/features/chat/replacement.js b/react/features/chat/replacement.jsindex 096ea23179..c814919ae6 100644--- a/react/features/chat/replacement.js+++ b/react/features/chat/replacement.js@@ -1,5 +1,22 @@import { regexes } from './smileys';+/* eslint-disable no-useless-escape, max-len */+const replacePatterns = {++ // URLs starting with http://, https://, or ftp://+ '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>':+ /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,++ // URLs starting with "www." (without // before it, or it'd re-link the ones done above).+ '$1<a href="https://$2" target="_blank" rel="noopener noreferrer">$2</a>':+ /(^|[^\/])(www\.[\S]+(\b|$))/gim,++ // Change email addresses to mailto: links.+ '<a href="mailto:$1">$1</a>':+ /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim+};+/* eslint-enable no-useless-escape, max-len */+/*** Processes links and smileys in "body".*@@ -8,39 +25,38 @@ import { regexes } from './smileys';*/export function processReplacements(body) {// make links clickable + add smileys- return smilify(linkify(body));-}---/**- * Finds and replaces all links in the links in "body" with an href tag.- *- * @param {string} inputText - The message body.- * @returns {string} The text replaced with HTML tags for links.- */-function linkify(inputText) {- let replacedText;- /* eslint-disable no-useless-escape, max-len */-- // URLs starting with http://, https://, or ftp://- const replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;+ // non of the patterns we search contains a space, that's why we tokenize it+ // and after processing each token we join it again with the results+ // making sure we do only one replacement for a token+ const tokens = body.split(' ');+ const resultText = [];- replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>');+ for (const token of tokens) {+ let replacedText;+ const tokenLength = token.length;- // URLs starting with "www." (without // before it, or it'd re-link the ones done above).- const replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;+ for (const newString in replacePatterns) { // eslint-disable-line guard-for-in, max-len+ const replacePattern = replacePatterns[newString];- replacedText = replacedText.replace(replacePattern2, '$1<a href="https://$2" target="_blank" rel="noopener noreferrer">$2</a>');+ replacedText = token.replace(replacePattern, newString);- // Change email addresses to mailto: links.- const replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;+ // replacement was done, stop doing any other replacements+ if (replacedText.length > tokenLength) {+ break;+ }+ replacedText = null;+ }- replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');+ // no replacement was done, then just check for smiley+ if (!replacedText) {+ replacedText = smilify(token);+ }- /* eslint-enable no-useless-escape */+ resultText.push(replacedText);+ }- return replacedText;+ return resultText.join(' ');}/**