From b4d14164bb47a76e62977447816fae5b65ea4da7 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 22 Jan 2018 21:52:32 +0000 Subject: [PATCH 1/2] The url detection in BBCode is too greedy --- include/bbcode.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 281eeeb02..cad7ddc92 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -971,11 +971,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa if (!$forplaintext) { // Autolink feature (thanks to http://code.seebz.net/p/autolink-php/) $autolink_regex = "`([^\]\=\"']|^)(https?\://[^\s<]+[^\s<\.\)])`ism"; - if ($simplehtml != 7) { - $Text = preg_replace($autolink_regex, '$1$2', $Text); - } else { - $Text = preg_replace($autolink_regex, '$1[url]$2[/url]', $Text); - + $autolink_regex = "/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism"; + $Text = preg_replace($autolink_regex, '$1[url]$2[/url]', $Text); + if ($simplehtml == 7) { $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text); $Text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text); } @@ -1047,7 +1045,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa $Text = preg_replace($expression, System::baseUrl()."/display/$1", $Text); if ($tryoembed) { - $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $tryoembed_callback, $Text); + // $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $tryoembed_callback, $Text); } $Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", From 2e333dea8fb7b9eaa8259469a1ac63d1772eb60e Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 22 Jan 2018 22:26:47 +0000 Subject: [PATCH 2/2] Code cleaned --- include/bbcode.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index cad7ddc92..3a187c281 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -970,7 +970,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text if (!$forplaintext) { // Autolink feature (thanks to http://code.seebz.net/p/autolink-php/) - $autolink_regex = "`([^\]\=\"']|^)(https?\://[^\s<]+[^\s<\.\)])`ism"; + // Currently disabled, since the function is too greedy + // $autolink_regex = "`([^\]\=\"']|^)(https?\://[^\s<]+[^\s<\.\)])`ism"; $autolink_regex = "/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism"; $Text = preg_replace($autolink_regex, '$1[url]$2[/url]', $Text); if ($simplehtml == 7) { @@ -1044,10 +1045,6 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa $expression = "=diaspora://.*?/post/([0-9A-Za-z\-_@.:]{15,254}[0-9A-Za-z])=ism"; $Text = preg_replace($expression, System::baseUrl()."/display/$1", $Text); - if ($tryoembed) { - // $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $tryoembed_callback, $Text); - } - $Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text);