From 80f3ca4ebbc99edd4a9a1109bb9d39f6df84e69e Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Fri, 29 Sep 2023 13:31:31 +0200 Subject: [PATCH] Improved description extras --- app/Helpers/Wrappers.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Helpers/Wrappers.php b/app/Helpers/Wrappers.php index 1d1e0cf..71356b6 100644 --- a/app/Helpers/Wrappers.php +++ b/app/Helpers/Wrappers.php @@ -96,13 +96,13 @@ class Wrappers { }); // Add URLs to video descriptions - // TODO: Make it work with unicode characters such as emojis $latte->addFunction('render_desc', function (string $desc, array $textExtras = []): string { $sanitizedDesc = htmlspecialchars($desc); $out = $sanitizedDesc; foreach ($textExtras as $extra) { $url = ''; - $text = mb_substr($desc, $extra->start, $extra->end - $extra->start, 'UTF-8'); + // We do -1 to also take the # or @ + $text = mb_substr($desc, $extra->start - 1, $extra->end - $extra->start, 'UTF-8'); switch ($extra->type) { // User URL case TextExtras::USER: @@ -114,7 +114,8 @@ class Wrappers { break; } - $out = str_replace($text, "$text", $out); + // We do \b to avoid non-strict matches ('#hi' would match with '#hii' and we don't want that) + $out = preg_replace("/$text\b/", "$text", $out); } return $out; });