From ee88de1ef994d77051657e94d8a30f734dd454a9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 22 Nov 2018 09:34:17 -0500 Subject: [PATCH] Normalize BBCode Hashtag replacement --- src/Content/Text/BBCode.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 9c9adec0fa..cb375dcd21 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);