From 3ea926550b8fdc89952193aa083112511b55922a Mon Sep 17 00:00:00 2001 From: Zed Date: Fri, 20 Sep 2019 01:46:20 +0200 Subject: [PATCH] Fix username linkification bug --- src/formatters.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/formatters.nim b/src/formatters.nim index 74c4e51..fdd3a8d 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -8,7 +8,7 @@ from unicode import Rune, `$` const urlRegex = re"((https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+([/\?][^\s\)]*)?)" emailRegex = re"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)" - usernameRegex = re"(^|[^A-z0-9_?])@([A-z0-9_]+)" + usernameRegex = re"(^|[^A-z0-9_?\/])@([A-z0-9_]+)" picRegex = re"pic.twitter.com/[^ ]+" ellipsisRegex = re" ?…" hashtagRegex = re"([^\S])?([#$][A-z0-9]+)" @@ -77,15 +77,15 @@ proc replaceUrl*(url: string; prefs: Prefs): string = proc linkifyText*(text: string; prefs: Prefs; rss=false): string = result = xmltree.escape(stripText(text)) - result = result.replace(ellipsisRegex, "") + result = result.replace(ellipsisRegex, " ") result = result.replace(emailRegex, reEmailToLink) - result = result.replace(hashtagRegex, reHashtagToLink) if rss: result = result.replace(urlRegex, reUrlToLink) result = result.replace(usernameRegex, reUsernameToFullLink) else: result = result.replace(urlRegex, reUrlToShortLink) result = result.replace(usernameRegex, reUsernameToLink) + result = result.replace(hashtagRegex, reHashtagToLink) result = result.replace(re"([^\s\(\n%])\s+([;.,!\)'%]|')", "$1") result = result.replace(re"^\.