From e79668ddf43cb66dc9535c521bf990ae42a6e6af Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 26 Jul 2022 15:37:17 +0000 Subject: fix lang tests if result is ambigous --- Zotlabs/Lib/MessageFilter.php | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php index 13ec78072..7d6dcbe8e 100644 --- a/Zotlabs/Lib/MessageFilter.php +++ b/Zotlabs/Lib/MessageFilter.php @@ -29,7 +29,19 @@ class MessageFilter { if (! $word) { continue; } - if (substr($word, 0, 1) === '#' && $tags) { + if (isset($lang) && ((strpos($word, 'lang=') === 0) || (strpos($word, 'lang!=') === 0))) { + if (!strlen($lang)) { + // Result is ambiguous. As we are matching deny rules only at this time, continue tests. + // Any matching deny rule concludes testing. + continue; + } + if (strpos($word, 'lang=') === 0 && strcasecmp($lang, trim(substr($word, 5))) == 0) { + return false; + } elseif (strpos($word, 'lang!=') === 0 && strcasecmp($lang, trim(substr($word, 6))) != 0) { + return false; + } + } + elseif (substr($word, 0, 1) === '#' && $tags) { foreach ($tags as $t) { if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) { return false; @@ -51,10 +63,6 @@ class MessageFilter { } } elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) { return false; - } elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) { - return false; - } elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) { - return false; } elseif (stristr($text, $word) !== false) { return false; } @@ -69,7 +77,19 @@ class MessageFilter { if (! $word) { continue; } - if (substr($word, 0, 1) === '#' && $tags) { + if (isset($lang) && ((strpos($word, 'lang=') === 0) || (strpos($word, 'lang!=') === 0))) { + if (!strlen($lang)) { + // Result is ambiguous. However we are checking allow rules + // and an ambiguous language is always permitted. + return true; + } + if (strpos($word, 'lang=') === 0 && strcasecmp($lang, trim(substr($word, 5))) == 0) { + return true; + } elseif (strpos($word, 'lang!=') === 0 && strcasecmp($lang, trim(substr($word, 6))) != 0) { + return true; + } + } + elseif (substr($word, 0, 1) === '#' && $tags) { foreach ($tags as $t) { if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) { return true; @@ -91,10 +111,6 @@ class MessageFilter { } } elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) { return true; - } elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) { - return true; - } elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) { - return true; } elseif (stristr($text, $word) !== false) { return true; } -- cgit v1.2.3