From 8f35ba4738af1d3d21deb01c6b2c7ad6c6af2bb6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 22 Oct 2021 11:14:07 +0200 Subject: [PATCH] Clean up initialization in `Censorship` - Use a regular foreach loop. - Use `ArrayUtil::trim()` which also removes empty elements by itself. --- .../system/message/censorship/Censorship.class.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/system/message/censorship/Censorship.class.php b/wcfsetup/install/files/lib/system/message/censorship/Censorship.class.php index d51c4f0a12..f25b7c1902 100644 --- a/wcfsetup/install/files/lib/system/message/censorship/Censorship.class.php +++ b/wcfsetup/install/files/lib/system/message/censorship/Censorship.class.php @@ -3,6 +3,7 @@ namespace wcf\system\message\censorship; use wcf\system\SingletonFactory; +use wcf\util\ArrayUtil; use wcf\util\StringUtil; /** @@ -45,15 +46,13 @@ class Censorship extends SingletonFactory protected function init() { // get words which should be censored - $censoredWords = \explode("\n", StringUtil::unifyNewlines(\mb_strtolower(CENSORED_WORDS))); + $censoredWords = ArrayUtil::trim(\explode( + "\n", + StringUtil::unifyNewlines(\mb_strtolower(CENSORED_WORDS)) + )); // format censored words - for ($i = 0, $length = \count($censoredWords); $i < $length; $i++) { - $censoredWord = StringUtil::trim($censoredWords[$i]); - if (empty($censoredWord)) { - continue; - } - + foreach ($censoredWords as $censoredWord) { $displayedCensoredWord = \str_replace(['~', '*'], '', $censoredWord); // check if censored word contains at least one delimiter -- 2.20.1