From c3e3e83a521b971cc90f17257bf2c4b793f26c68 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 4 Aug 2019 10:22:23 -0400 Subject: [PATCH] Improve BBCode:toPlaintext - Fix issue where matching literal square brackets were removed with their content - Fix issue where content without line feeds between BBCode tags would end up compacted in plain text - Update extr calls to BBCode::toPlaintext in api --- include/api.php | 4 ++-- src/Content/Text/BBCode.php | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/api.php b/include/api.php index 543c018279..a7d25c83f0 100644 --- a/include/api.php +++ b/include/api.php @@ -614,7 +614,7 @@ function api_get_user(App $a, $contact_id = null) 'name' => $contact["name"], 'screen_name' => (($contact['nick']) ? $contact['nick'] : $contact['name']), 'location' => ($contact["location"] != "") ? $contact["location"] : ContactSelector::networkToName($contact['network'], $contact['url']), - 'description' => HTML::toPlaintext(BBCode::toPlaintext($contact["about"])), + 'description' => BBCode::toPlaintext($contact["about"]), 'profile_image_url' => $contact["micro"], 'profile_image_url_https' => $contact["micro"], 'profile_image_url_profile_size' => $contact["thumb"], @@ -693,7 +693,7 @@ function api_get_user(App $a, $contact_id = null) 'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']), 'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']), 'location' => $location, - 'description' => HTML::toPlaintext(BBCode::toPlaintext($description)), + 'description' => BBCode::toPlaintext($description), 'profile_image_url' => $uinfo[0]['micro'], 'profile_image_url_https' => $uinfo[0]['micro'], 'profile_image_url_profile_size' => $uinfo[0]["thumb"], diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b2d4ebb5d7..b012e79fb2 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -357,10 +357,7 @@ class BBCode extends BaseObject */ public static function toPlaintext($text, $keep_urls = true) { - $naked_text = preg_replace('/\[.+?\]/','', $text); - if (!$keep_urls) { - $naked_text = preg_replace('#https?\://[^\s<]+[^\s\.\)]#i', '', $naked_text); - } + $naked_text = HTML::toPlaintext(BBCode::convert($text, false, 0, true), 0, !$keep_urls); return $naked_text; } -- 2.39.5