Prevent multiple replacements for the same emoji in Protocol\ActivityPub\Processor::replaceEmojis

This commit is contained in:
Hypolite Petovan 2020-11-11 18:28:26 -05:00
parent 9e4a0bf212
commit a8f16788f4

View file

@ -75,10 +75,15 @@ class Processor
*/
private static function replaceEmojis($body, array $emojis)
{
foreach ($emojis as $emoji) {
$replace = '[class=emoji mastodon][img=' . $emoji['href'] . ']' . $emoji['name'] . '[/img][/class]';
$body = str_replace($emoji['name'], $replace, $body);
}
$body = strtr($body,
array_combine(
array_column($emojis, 'name'),
array_map(function ($emoji) {
return '[class=emoji mastodon][img=' . $emoji['href'] . ']' . $emoji['name'] . '[/img][/class]';
}, $emojis)
)
);
return $body;
}