From 87f79381d96ef0f154fe026d26135fdcf6c26186 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 19 Dec 2025 08:24:22 +0000 Subject: [PATCH] MessageFilter: move decoding to the caller and also check the summary field --- Zotlabs/Lib/Activity.php | 3 ++- Zotlabs/Lib/Libzot.php | 3 ++- Zotlabs/Lib/MessageFilter.php | 5 ++--- include/feedutils.php | 6 ++++-- include/items.php | 7 ++++--- tests/unit/Lib/MessageFilterTest.php | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 7dd2af813..d5619383c 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2928,9 +2928,10 @@ class Activity { if ($incl || $excl) { $plaintext = prepare_text($item['body'], ((isset($item['mimetype'])) ? $item['mimetype'] : 'text/bbcode')); + $plaintext = html2plain((isset($item['summary']) && $item['summary']) ? $item['summary'] . ' ' . $plaintext : $plaintext); $plaintext = html2plain((isset($item['title']) && $item['title']) ? $item['title'] . ' ' . $plaintext : $plaintext); - if (!(new MessageFilter($item, $incl, $excl, ['plaintext' => $plaintext]))->evaluate()) { + if (!(new MessageFilter($item, html_entity_decode($incl), html_entity_decode($excl), ['plaintext' => $plaintext]))->evaluate()) { logger('post is filtered'); return; } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index c4f172365..1b7a1f0a5 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1654,9 +1654,10 @@ class Libzot { if ($incl || $excl) { $plaintext = prepare_text($arr['body'], ((isset($arr['mimetype'])) ? $arr['mimetype'] : 'text/bbcode')); + $plaintext = html2plain((isset($arr['summary']) && $arr['summary']) ? $arr['summary'] . ' ' . $plaintext : $plaintext); $plaintext = html2plain((isset($arr['title']) && $arr['title']) ? $arr['title'] . ' ' . $plaintext : $plaintext); - if (!(new MessageFilter($arr, $incl, $excl, ['plaintext' => $plaintext]))->evaluate()) { + if (!(new MessageFilter($arr, html_entity_decode($incl), html_entity_decode($excl), ['plaintext' => $plaintext]))->evaluate()) { logger('post is filtered'); $local_public = false; continue; diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php index 5212f008d..2b795b80b 100644 --- a/Zotlabs/Lib/MessageFilter.php +++ b/Zotlabs/Lib/MessageFilter.php @@ -20,10 +20,9 @@ class MessageFilter public function __construct($item, $include = '', $exclude = '', $options = []) { $this->item = $item; - $this->include = html_entity_decode($include); - $this->exclude = html_entity_decode($exclude); + $this->include = $include; + $this->exclude = $exclude; $this->options = $options; - $this->setup(); } diff --git a/include/feedutils.php b/include/feedutils.php index d4a6345eb..0a9c37b11 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1353,9 +1353,10 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if ($incl || $excl) { $plaintext = prepare_text($datarray['body'], ((isset($datarray['mimetype'])) ? $datarray['mimetype'] : 'text/bbcode')); + $plaintext = html2plain((isset($datarray['summary']) && $datarray['summary']) ? $datarray['summary'] . ' ' . $plaintext : $plaintext); $plaintext = html2plain((isset($datarray['title']) && $datarray['title']) ? $datarray['title'] . ' ' . $plaintext : $plaintext); - if (!(new MessageFilter($datarray, $incl, $excl, ['plaintext' => $plaintext]))->evaluate()) { + if (!(new MessageFilter($datarray, html_entity_decode($incl), html_entity_decode($excl), ['plaintext' => $plaintext]))->evaluate()) { logger('post is filtered'); continue; } @@ -1523,9 +1524,10 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if ($incl || $excl) { $plaintext = prepare_text($datarray['body'], ((isset($datarray['mimetype'])) ? $datarray['mimetype'] : 'text/bbcode')); + $plaintext = html2plain((isset($datarray['summary']) && $datarray['summary']) ? $datarray['summary'] . ' ' . $plaintext : $plaintext); $plaintext = html2plain((isset($datarray['title']) && $datarray['title']) ? $datarray['title'] . ' ' . $plaintext : $plaintext); - if (!(new MessageFilter($datarray, $incl, $excl, ['plaintext' => $plaintext]))->evaluate()) { + if (!(new MessageFilter($datarray, html_entity_decode($incl), html_entity_decode($excl), ['plaintext' => $plaintext]))->evaluate()) { logger('post is filtered'); continue; } diff --git a/include/items.php b/include/items.php index 430a740b9..420d731f5 100644 --- a/include/items.php +++ b/include/items.php @@ -3604,7 +3604,7 @@ function check_item_source($uid, $item) { return true; } - if ((new MessageFilter($item, $r[0]['src_patt'], EMPTY_STR))->evaluate()) { + if ((new MessageFilter($item, html_entity_decode($r[0]['src_patt']), EMPTY_STR))->evaluate()) { logger('source: text filter success'); return true; } @@ -3627,10 +3627,11 @@ function post_is_importable($channel_id, $item, $abook) { $excl = PConfig::get($channel_id, 'system', 'message_filter_excl', EMPTY_STR); $plaintext = prepare_text($item['body'], ((isset($item['mimetype'])) ? $item['mimetype'] : 'text/bbcode')); + $plaintext = html2plain((isset($item['summary']) && $item['summary']) ? $item['summary'] . ' ' . $plaintext : $plaintext); $plaintext = html2plain((isset($item['title']) && $item['title']) ? $item['title'] . ' ' . $plaintext : $plaintext); if ($incl || $excl) { - if (!(new MessageFilter($item, $incl, $excl, ['plaintext' => $plaintext]))->evaluate()) { + if (!(new MessageFilter($item, html_entity_decode($incl), html_entity_decode($excl), ['plaintext' => $plaintext]))->evaluate()) { logger('MessageFilter: channel blocked content', LOGGER_DEBUG, LOG_INFO); return false; } @@ -3655,7 +3656,7 @@ function post_is_importable($channel_id, $item, $abook) { } // A negative assessment for any individual connections is an instant fail - if (!(new MessageFilter($item, $ab['abook_incl'], $ab['abook_excl'], ['plaintext' => $plaintext]))->evaluate()) { + if (!(new MessageFilter($item, html_entity_decode($ab['abook_incl']), html_entity_decode($ab['abook_excl']), ['plaintext' => $plaintext]))->evaluate()) { logger('MessageFilter: connection blocked content', LOGGER_DEBUG, LOG_INFO); return false; } diff --git a/tests/unit/Lib/MessageFilterTest.php b/tests/unit/Lib/MessageFilterTest.php index 9680dcc69..fc53d8cb4 100644 --- a/tests/unit/Lib/MessageFilterTest.php +++ b/tests/unit/Lib/MessageFilterTest.php @@ -174,7 +174,7 @@ class MessageFilterTest extends UnitTestCase { ], 'item.item_thread_top = 1 and item.item_private < 1 in excl encoded' => [ '', - "?item_thread_top == 1 && ?item_private < 1 ", + html_entity_decode("?item_thread_top == 1 && ?item_private < 1 "), false ], 'item.item_thread_top = 1 or item.item_private = 0 in excl' => [