From d1eb1ec0f4af2fab5db039855c4471c83444c9aa Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 12 Oct 2023 21:23:08 +0000 Subject: [PATCH] Use "IntlChar" for the emoji detection --- src/Content/Smilies.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 8744e19995..7d3e4073f4 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -296,7 +296,22 @@ class Smilies { // Strips all whitespace $conv = preg_replace('#\s#u', '', html_entity_decode($body)); - // @FIXME Emojis are almost always 4 byte Unicode characters, except when they include the zero-width joiner character, encoded on 3 bytes - return (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4)); + if (empty($conv)) { + return false; + } + + if (!class_exists('IntlChar')) { + // Most Emojis are 4 byte Unicode characters, so this is a good workaround, when IntlChar does not exist on the system + return strlen($conv) / mb_strlen($conv) == 4; + } + + for ($i = 0; $i < mb_strlen($conv); $i++) { + $character = mb_substr($conv, $i, 1); + + if (\IntlChar::isalnum($character)) { + return false; + } + } + return true; } }