From f9ecbbd74333f974905dd899a143dc61d01a699a Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Tue, 16 Jun 2020 16:34:16 -0400
Subject: [PATCH] Exclude [img] tags from tag replacement

- It broke image captions by inserting an HTML link inside an HTML attribute
---
 mod/item.php                | 2 +-
 src/Content/Text/BBCode.php | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mod/item.php b/mod/item.php
index 651c2224cb..6b99051328 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -375,7 +375,7 @@ function item_post(App $a) {
 	$only_to_forum = false;
 	$forum_contact = [];
 
-	$body = BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code'], function ($body) use ($profile_uid, $network, $str_contact_allow, &$inform, &$private_forum, &$private_id, &$only_to_forum, &$forum_contact) {
+	$body = BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network, $str_contact_allow, &$inform, &$private_forum, &$private_id, &$only_to_forum, &$forum_contact) {
 		$tags = BBCode::getTags($body);
 
 		$tagged = [];
diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php
index d7fda23aeb..09d0310686 100644
--- a/src/Content/Text/BBCode.php
+++ b/src/Content/Text/BBCode.php
@@ -2188,7 +2188,7 @@ class BBCode
 	 */
 	public static function setMentions($body, $profile_uid = 0, $network = '')
 	{
-		BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code'], function ($body) use ($profile_uid, $network) {
+		BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) {
 			$tags = BBCode::getTags($body);
 
 			$tagged = [];
@@ -2211,7 +2211,7 @@ class BBCode
 					}
 				}
 
-			$success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network);
+				$success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network);
 
 				if ($success['replaced']) {
 					$tagged[] = $tag;