Add unit tests for Smilies::isEmojiPost

- Current implementation is failing tests with emojis including the zero-width-joiner character, encoded on 3 bytes only.
This commit is contained in:
Hypolite Petovan 2023-08-29 22:16:09 -04:00
parent 6ed440718d
commit 059a111282
2 changed files with 73 additions and 1 deletions

View file

@ -289,11 +289,12 @@ class Smilies
/**
* Checks if the body only contains 4 byte unicode characters.
*
* @param string $body
* @param string $body Possibly-HTML post body
* @return boolean
*/
public static function isEmojiPost(string $body): bool
{
// Strips all whitespace
$conv = preg_replace('#\s#u', '', html_entity_decode($body));
// Emojis are always 4 byte Unicode characters
return (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4));