Move autolinker execution earlier in BBCode::convert

- Prevents already replaced HTML links (like in [audio] tag) to be doubled
- Add test for it
This commit is contained in:
Hypolite Petovan 2019-09-25 20:25:42 -04:00
parent 3ac6961da5
commit d8484e65bd
2 changed files with 16 additions and 6 deletions

View file

@ -1466,6 +1466,11 @@ class BBCode extends BaseObject
$text = str_replace('[hr]', '<hr />', $text);
if (!$for_plaintext) {
// Autolinker for isolated URLs
$text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
}
// This is actually executed in Item::prepareBody()
$nosmile = strpos($text, '[nosmile]') !== false;
@ -1648,9 +1653,7 @@ class BBCode extends BaseObject
$text = Smilies::replace($text);
}
// 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 (!$for_plaintext) {
$text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
if (in_array($simple_html, [7, 9])) {
$text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
$text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);