diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php
index 9c9adec0f..cb375dcd2 100644
--- a/src/Content/Text/BBCode.php
+++ b/src/Content/Text/BBCode.php
@@ -28,6 +28,7 @@ use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
+use Friendica\Util\XML;
class BBCode extends BaseObject
{
@@ -1340,15 +1341,21 @@ class BBCode extends BaseObject
$expression = "=diaspora://.*?/post/([0-9A-Za-z\-_@.:]{15,254}[0-9A-Za-z])=ism";
$text = preg_replace($expression, System::baseUrl()."/display/$1", $text);
- $text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- '$1$3', $text);
-
- $text = preg_replace("/\[url\=([$URLSearchString]*)\]#(.*?)\[\/url\]/ism",
- '#$2', $text);
+ /* Tag conversion
+ * Supports:
+ * - #[url=][/url]
+ * - [url=]#[/url]
+ */
+ $text = preg_replace_callback("/(?:#\[url\=[$URLSearchString]*\]|\[url\=[$URLSearchString]*\]#)(.*?)\[\/url\]/ism", function($matches) {
+ return '#'
+ . XML::escape($matches[1])
+ . '';
+ }, $text);
$text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $text);
$text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text);
- //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '$2', $Text);
// Red compatibility, though the link can't be authenticated on Friendica
$text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $text);