Merge pull request #10181 from annando/less-greedy

Less greedy when replacing attachment elements
This commit is contained in:
Tobias Diekershoff 2021-04-29 06:51:12 +02:00 committed by GitHub
commit 33e1a3f64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -408,7 +408,7 @@ class BBCode
*/ */
public static function removeAttachment($body, $no_link_desc = false) public static function removeAttachment($body, $no_link_desc = false)
{ {
return preg_replace_callback("/\s*\[attachment (.*)\](.*?)\[\/attachment\]\s*/ism", return preg_replace_callback("/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
function ($match) use ($no_link_desc) { function ($match) use ($no_link_desc) {
$attach_data = self::getAttachmentData($match[0]); $attach_data = self::getAttachmentData($match[0]);
if (empty($attach_data['url'])) { if (empty($attach_data['url'])) {

View File

@ -1706,7 +1706,7 @@ class Item
return ("[bookmark=" . str_replace("#", "#", $match[1]) . "]" . str_replace("#", "#", $match[2]) . "[/bookmark]"); return ("[bookmark=" . str_replace("#", "#", $match[1]) . "]" . str_replace("#", "#", $match[2]) . "[/bookmark]");
}, $body); }, $body);
$body = preg_replace_callback("/\[attachment (.*)\](.*?)\[\/attachment\]/ism", $body = preg_replace_callback("/\[attachment (.*?)\](.*?)\[\/attachment\]/ism",
function ($match) { function ($match) {
return ("[attachment " . str_replace("#", "#", $match[1]) . "]" . $match[2] . "[/attachment]"); return ("[attachment " . str_replace("#", "#", $match[1]) . "]" . $match[2] . "[/attachment]");
}, $body); }, $body);
@ -2640,7 +2640,7 @@ class Item
} }
$orig_body = $item['body']; $orig_body = $item['body'];
$item['body'] = preg_replace("/\s*\[attachment .*\].*?\[\/attachment\]\s*/ism", '', $item['body']); $item['body'] = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $item['body']);
self::putInCache($item); self::putInCache($item);
$item['body'] = $orig_body; $item['body'] = $orig_body;
$s = $item["rendered-html"]; $s = $item["rendered-html"];