From 82a9fdefe7938c4c182dd14b46b8aa1e7d74eb18 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 30 Jun 2021 05:23:09 +0300 Subject: [PATCH] Profile: Fix parsing multiple links in bio (#1219) --- src/components/common/helpers/renderText.tsx | 9 ++++----- src/config.ts | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/common/helpers/renderText.tsx b/src/components/common/helpers/renderText.tsx index 98da3f83f..a8ce3e834 100644 --- a/src/components/common/helpers/renderText.tsx +++ b/src/components/common/helpers/renderText.tsx @@ -1,7 +1,7 @@ import React from '../../../lib/teact/teact'; import EMOJI_REGEX, { removeVS16s } from '../../../lib/twemojiRegex'; -import { RE_LINK_TEMPLATE } from '../../../config'; +import { RE_LINK_TEMPLATE, RE_MENTION_TEMPLATE } from '../../../config'; import { IS_EMOJI_SUPPORTED } from '../../../util/environment'; import { nativeToUnfified } from '../../../util/emoji'; import buildClassName from '../../../util/buildClassName'; @@ -177,8 +177,7 @@ function addHighlight(textParts: TextPart[], highlight: string | undefined): Tex }, [] as TextPart[]); } -const RE_LINK = new RegExp(RE_LINK_TEMPLATE, 'ig'); -const RE_MENTION = /@[\w\d_-]+/ig; +const RE_LINK = new RegExp(`${RE_LINK_TEMPLATE}|${RE_MENTION_TEMPLATE}`, 'ig'); function addLinks(textParts: TextPart[]): TextPart[] { return textParts.reduce((result, part) => { @@ -186,8 +185,8 @@ function addLinks(textParts: TextPart[]): TextPart[] { return [...result, part]; } - const links = [...(part.match(RE_LINK) || []), ...(part.match(RE_MENTION) || [])]; - if (!links.length) { + const links = part.match(RE_LINK); + if (!links || !links.length) { return [...result, part]; } diff --git a/src/config.ts b/src/config.ts index 3b96175b5..541d721b1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -115,6 +115,7 @@ export const CONTENT_TYPES_FOR_QUICK_UPLOAD = 'image/png,image/gif,image/jpeg,vi // eslint-disable-next-line max-len export const RE_LINK_TEMPLATE = '((ftp|https?):\\/\\/)?((www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6})\\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)'; +export const RE_MENTION_TEMPLATE = '(@[\\w\\d_-]+)'; export const RE_TME_LINK = /^(?:https?:\/\/)?(?:t\.me\/)([\d\w_]+)(?:\/([\d]+))?$/gm; export const RE_TME_INVITE_LINK = /^(?:https?:\/\/)?(?:t\.me\/joinchat\/)([\d\w_-]+)?$/gm;