]> git.mxchange.org Git - friendica.git/commitdiff
Add no-parsing block escaping in BBCode::setMentions
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 10 Jun 2020 13:55:52 +0000 (09:55 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 10 Jun 2020 14:16:07 +0000 (10:16 -0400)
src/Content/Text/BBCode.php

index 70c7eb92a9d14343c6aa196f05392f49e9e10d12..d7fda23aebedd3def4bd7bb104c04088a56435c7 100644 (file)
@@ -2188,34 +2188,38 @@ class BBCode
         */
        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 = [];
-               $inform = '';
+                       $tagged = [];
+                       $inform = '';
 
-               foreach ($tags as $tag) {
-                       $tag_type = substr($tag, 0, 1);
+                       foreach ($tags as $tag) {
+                               $tag_type = substr($tag, 0, 1);
 
-                       if ($tag_type == Tag::TAG_CHARACTER[Tag::HASHTAG]) {
-                               continue;
-                       }
+                               if ($tag_type == Tag::TAG_CHARACTER[Tag::HASHTAG]) {
+                                       continue;
+                               }
 
-                       /*
-                        * If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
-                        * Robert Johnson should be first in the $tags array
-                        */
-                       foreach ($tagged as $nextTag) {
-                               if (stristr($nextTag, $tag . ' ')) {
-                                       continue 2;
+                               /*
+                                * If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
+                                * Robert Johnson should be first in the $tags array
+                                */
+                               foreach ($tagged as $nextTag) {
+                                       if (stristr($nextTag, $tag . ' ')) {
+                                               continue 2;
+                                       }
                                }
-                       }
 
                        $success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network);
 
-                       if ($success['replaced']) {
-                               $tagged[] = $tag;
+                               if ($success['replaced']) {
+                                       $tagged[] = $tag;
+                               }
                        }
-               }
+
+                       return $body;
+               });
 
                return $body;
        }