Add no-parsing block escaping in BBCode::setMentions

This commit is contained in:
Hypolite Petovan 2020-06-10 09:55:52 -04:00
parent eaa7740da6
commit 9b2d758c1a

View file

@ -2188,34 +2188,38 @@ class BBCode
*/ */
public static function setMentions($body, $profile_uid = 0, $network = '') public static function setMentions($body, $profile_uid = 0, $network = '')
{ {
$tags = BBCode::getTags($body); BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code'], function ($body) use ($profile_uid, $network) {
$tags = BBCode::getTags($body);
$tagged = []; $tagged = [];
$inform = ''; $inform = '';
foreach ($tags as $tag) { foreach ($tags as $tag) {
$tag_type = substr($tag, 0, 1); $tag_type = substr($tag, 0, 1);
if ($tag_type == Tag::TAG_CHARACTER[Tag::HASHTAG]) { if ($tag_type == Tag::TAG_CHARACTER[Tag::HASHTAG]) {
continue; continue;
} }
/* /*
* If we already tagged 'Robert Johnson', don't try and tag 'Robert'. * If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
* Robert Johnson should be first in the $tags array * Robert Johnson should be first in the $tags array
*/ */
foreach ($tagged as $nextTag) { foreach ($tagged as $nextTag) {
if (stristr($nextTag, $tag . ' ')) { if (stristr($nextTag, $tag . ' ')) {
continue 2; continue 2;
}
} }
}
$success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network); $success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network);
if ($success['replaced']) { if ($success['replaced']) {
$tagged[] = $tag; $tagged[] = $tag;
}
} }
}
return $body;
});
return $body; return $body;
} }