From: Alexander Ebert Date: Tue, 10 Feb 2015 13:41:18 +0000 (+0100) Subject: Improved censorship to properly handle delimiters in forbidden words X-Git-Tag: 2.1.0_RC_1~41 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4688f456dcf6d7b8996d4439882b468c6e9bccbf;p=GitHub%2FWoltLab%2FWCF.git Improved censorship to properly handle delimiters in forbidden words --- 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 4387bb3ec4..7e6b68feaa 100644 --- a/wcfsetup/install/files/lib/system/message/censorship/Censorship.class.php +++ b/wcfsetup/install/files/lib/system/message/censorship/Censorship.class.php @@ -1,14 +1,13 @@ * @package com.woltlab.wcf * @subpackage system.message.censorship @@ -47,7 +46,25 @@ class Censorship extends SingletonFactory { $censoredWords = explode("\n", StringUtil::unifyNewlines(mb_strtolower(CENSORED_WORDS))); // format censored words - $this->censoredWords = ArrayUtil::trim($censoredWords); + for ($i = 0, $length = count($censoredWords); $i < $length; $i++) { + $censoredWord = StringUtil::trim($censoredWords[$i]); + if (empty($censoredWord)) { + continue; + } + + $displayedCensoredWord = str_replace(array('~', '*'), '', $censoredWord); + + // check if censored word contains at least one delimiter + if (preg_match('!'.$this->delimiters.'+!', $censoredWord)) { + // remove delimiters + $censoredWord = preg_replace('!'.$this->delimiters.'!', '', $censoredWord); + + // enforce partial matching + $censoredWord = '~' . $censoredWord; + } + + $this->censoredWords[$displayedCensoredWord] = $censoredWord; + } } /** @@ -72,7 +89,7 @@ class Censorship extends SingletonFactory { // check each word if it's censored. for ($i = 0, $count = count($this->words); $i < $count; $i++) { $word = $this->words[$i]; - foreach ($this->censoredWords as $censoredWord) { + foreach ($this->censoredWords as $displayedCensoredWord => $censoredWord) { // check for direct matches ("badword" == "badword") if ($censoredWord == $word) { // store censored word @@ -122,11 +139,11 @@ class Censorship extends SingletonFactory { } // store censored word - if (isset($this->matches[$censoredWord])) { - $this->matches[$censoredWord]++; + if (isset($this->matches[$displayedCensoredWord])) { + $this->matches[$displayedCensoredWord]++; } else { - $this->matches[$censoredWord] = 1; + $this->matches[$displayedCensoredWord] = 1; } continue 2;