From 7ca3591920b1cf1619f6c89e1e3c378cffd317d2 Mon Sep 17 00:00:00 2001 From: jackyzy823 Date: Mon, 14 Feb 2022 09:20:32 +0100 Subject: [PATCH 1/2] fix non-ascii hashtag regex --- src/experimental/parser/user.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/experimental/parser/user.nim b/src/experimental/parser/user.nim index dc760f0..bf8c5ba 100644 --- a/src/experimental/parser/user.nim +++ b/src/experimental/parser/user.nim @@ -1,14 +1,14 @@ -import std/[algorithm, unicode, re, strutils, strformat, options] +import std/[algorithm, unicode, re, strutils, strformat, options, nre] import jsony import utils, slices import ../types/user as userType from ../../types import User, Error let - unRegex = re"(^|[^A-z0-9-_./?])@([A-z0-9_]{1,15})" + unRegex = re.re"(^|[^A-z0-9-_./?])@([A-z0-9_]{1,15})" unReplace = "$1@$2" - htRegex = re"(^|[^\w-_./?])([##$])([\w_]+)" + htRegex = nre.re"(*U)(^|[^\w-_./?])([##$])([\w_]+)" htReplace = "$1$2$3" proc expandUserEntities(user: var User; raw: RawUser) = @@ -29,7 +29,7 @@ proc expandUserEntities(user: var User; raw: RawUser) = user.bio = orig.replacedWith(replacements, 0 .. orig.len) .replacef(unRegex, unReplace) - .replacef(htRegex, htReplace) + .replace(htRegex, htReplace) proc getBanner(user: RawUser): string = if user.profileBannerUrl.len > 0: From c7a78a7f434aeb5ce625a3c9e207a6217c741e09 Mon Sep 17 00:00:00 2001 From: jackyzy823 Date: Mon, 14 Feb 2022 09:38:46 +0100 Subject: [PATCH 2/2] fix slashes between hastags --- src/experimental/parser/user.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/experimental/parser/user.nim b/src/experimental/parser/user.nim index bf8c5ba..715c9a9 100644 --- a/src/experimental/parser/user.nim +++ b/src/experimental/parser/user.nim @@ -8,7 +8,7 @@ let unRegex = re.re"(^|[^A-z0-9-_./?])@([A-z0-9_]{1,15})" unReplace = "$1@$2" - htRegex = nre.re"(*U)(^|[^\w-_./?])([##$])([\w_]+)" + htRegex = nre.re"""(*U)(^|[^\w-_.?])([##$])([\w_]*+)(?!|">|#)""" htReplace = "$1$2$3" proc expandUserEntities(user: var User; raw: RawUser) =