From e64a8ea65d445d582a4f049de369f7de343cdced Mon Sep 17 00:00:00 2001 From: Hafiq Date: Sun, 20 Oct 2019 15:25:32 +0800 Subject: [PATCH 1/7] Fix Test and Minor Changes on CensorWord class --- .idea/$CACHE_FILE$ | 6 + .idea/.gitignore | 2 + .idea/banbuilder.iml | 49 ++ .idea/composerJson.xml | 10 + .idea/dictionaries/hafiq.xml | 9 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/php-test-framework.xml | 14 + .idea/php.xml | 56 +++ .idea/vcs.xml | 6 + src/CensorWords.php | 90 ++-- src/dict/cs.php | 415 +++++++++-------- src/dict/de.php | 4 +- src/dict/en-base.php | 80 ++-- src/dict/en-uk.php | 255 ++++++----- src/dict/en-us.php | 81 ++-- src/dict/es.php | 116 ++--- src/dict/fi.php | 834 +++++++++++++++++------------------ src/dict/fr.php | 122 ++--- src/dict/id.php | 86 ++++ src/dict/it.php | 442 +++++++++---------- src/dict/jp.php | 90 ++-- src/dict/kr.php | 100 ++--- src/dict/my.php | 39 ++ src/dict/nl.php | 152 +++---- src/dict/no.php | 246 +++++------ tests/CensorTest.php | 100 +++-- tests/testFile/my.php | 39 ++ 28 files changed, 1912 insertions(+), 1545 deletions(-) create mode 100644 .idea/$CACHE_FILE$ create mode 100644 .idea/.gitignore create mode 100644 .idea/banbuilder.iml create mode 100644 .idea/composerJson.xml create mode 100644 .idea/dictionaries/hafiq.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/php-test-framework.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml create mode 100644 src/dict/id.php create mode 100644 src/dict/my.php create mode 100644 tests/testFile/my.php diff --git a/.idea/$CACHE_FILE$ b/.idea/$CACHE_FILE$ new file mode 100644 index 0000000..6cb8985 --- /dev/null +++ b/.idea/$CACHE_FILE$ @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/banbuilder.iml b/.idea/banbuilder.iml new file mode 100644 index 0000000..1e840f3 --- /dev/null +++ b/.idea/banbuilder.iml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/composerJson.xml b/.idea/composerJson.xml new file mode 100644 index 0000000..1b07430 --- /dev/null +++ b/.idea/composerJson.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/hafiq.xml b/.idea/dictionaries/hafiq.xml new file mode 100644 index 0000000..79de7f9 --- /dev/null +++ b/.idea/dictionaries/hafiq.xml @@ -0,0 +1,9 @@ + + + + badwords + leet + newstring + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5ba215b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml new file mode 100644 index 0000000..0d881d6 --- /dev/null +++ b/.idea/php-test-framework.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..85fa413 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/CensorWords.php b/src/CensorWords.php index a453422..95f72c8 100644 --- a/src/CensorWords.php +++ b/src/CensorWords.php @@ -2,6 +2,8 @@ namespace Snipe\BanBuilder; +use http\Exception\RuntimeException; + class CensorWords { public $badwords; @@ -18,16 +20,19 @@ class CensorWords */ private $whiteList = []; + /** + * @var string + */ + private $replacer = '*'; + /** * @var string */ private $whiteListPlaceHolder = ' {whiteList[i]} '; - public function __construct() + public function __construct($dictionary = ['en-base', 'en-us']) { - $this->badwords = array(); - $this->replacer = '*'; - $this->setDictionary('en-us'); + $this->setDictionary($dictionary); } @@ -37,10 +42,11 @@ public function __construct() * or an array of strings to multiple paths * * @param string|array - * @throws \RuntimeException if a dictionary file is not found */ public function setDictionary($dictionary) { + $this->censorChecks = null; + $this->badwords = []; $this->badwords = $this->readBadWords($dictionary); } @@ -50,10 +56,10 @@ public function setDictionary($dictionary) * or an array of strings to multiple paths * * @param string|array - * @throws \RuntimeException if a dictionary file is not found */ public function addDictionary($dictionary) { + $this->censorChecks = null; //refresh censorChecks $this->badwords = array_merge($this->badwords, $this->readBadWords($dictionary)); } @@ -73,13 +79,14 @@ public function addFromArray($words) * * @param string|array a language identifier or path for a dictionary (or an array of identifiers/paths) * - * @throws \RuntimeException if a dictionary file is not found - * * @return array de-duplicated array of bad words */ private function readBadWords($dictionary) { - $badwords = array(); + if (!$dictionary) + throw new RuntimeException("Dictionary Path Cannot be Null"); + + $badwords = []; $baseDictPath = __DIR__ . DIRECTORY_SEPARATOR . 'dict' . DIRECTORY_SEPARATOR; if (is_array($dictionary)) { @@ -91,17 +98,17 @@ private function readBadWords($dictionary) // just a single string, not an array if (is_string($dictionary)) { if (file_exists($baseDictPath . $dictionary . '.php')) { - include $baseDictPath . $dictionary . '.php'; + $badwords = array_merge($badwords, require $baseDictPath . $dictionary . '.php'); } elseif (file_exists($dictionary)) { - include $dictionary; + $badwords = array_merge($badwords, require $dictionary); } else { - throw new \RuntimeException('Dictionary file not found: ' . $dictionary); + $badwords = array_merge($badwords, []); //instead of throw exception, just return empty array } } // counting values and then only returning the keys is said // to be more efficient than array_values(array_unique()) - return array_keys(array_count_values($badwords)); + return $badwords; } /** @@ -138,7 +145,6 @@ private function replaceWhiteListed($string, $reverse = false) $string = str_replace($list['word'], $placeHolder, $string); } } - return $string; } @@ -183,32 +189,32 @@ private function generateCensorChecks($fullWords = false) // generate censor checks as soon as we load the dictionary // utilize leet equivalents as well $leet_replace = array(); - $leet_replace['a'] = '(a|a\.|a\-|4|@|Á|á|À|Â|à|Â|â|Ä|ä|Ã|ã|Å|å|α|Δ|Λ|λ)'; - $leet_replace['b'] = '(b|b\.|b\-|8|\|3|ß|Β|β)'; - $leet_replace['c'] = '(c|c\.|c\-|Ç|ç|¢|€|<|\(|{|©)'; - $leet_replace['d'] = '(d|d\.|d\-|∂|\|\)|Þ|þ|Ð|ð)'; - $leet_replace['e'] = '(e|e\.|e\-|3|€|È|è|É|é|Ê|ê|∑)'; - $leet_replace['f'] = '(f|f\.|f\-|ƒ)'; - $leet_replace['g'] = '(g|g\.|g\-|6|9)'; - $leet_replace['h'] = '(h|h\.|h\-|Η)'; - $leet_replace['i'] = '(i|i\.|i\-|!|\||\]\[|]|1|∫|Ì|Í|Î|Ï|ì|í|î|ï)'; - $leet_replace['j'] = '(j|j\.|j\-)'; - $leet_replace['k'] = '(k|k\.|k\-|Κ|κ)'; - $leet_replace['l'] = '(l|1\.|l\-|!|\||\]\[|]|£|∫|Ì|Í|Î|Ï)'; - $leet_replace['m'] = '(m|m\.|m\-)'; - $leet_replace['n'] = '(n|n\.|n\-|η|Ν|Π)'; - $leet_replace['o'] = '(o|o\.|o\-|0|Ο|ο|Φ|¤|°|ø)'; - $leet_replace['p'] = '(p|p\.|p\-|ρ|Ρ|¶|þ)'; - $leet_replace['q'] = '(q|q\.|q\-)'; - $leet_replace['r'] = '(r|r\.|r\-|®)'; - $leet_replace['s'] = '(s|s\.|s\-|5|\$|§)'; - $leet_replace['t'] = '(t|t\.|t\-|Τ|τ|7)'; - $leet_replace['u'] = '(u|u\.|u\-|υ|µ)'; - $leet_replace['v'] = '(v|v\.|v\-|υ|ν)'; - $leet_replace['w'] = '(w|w\.|w\-|ω|ψ|Ψ)'; - $leet_replace['x'] = '(x|x\.|x\-|Χ|χ)'; - $leet_replace['y'] = '(y|y\.|y\-|¥|γ|ÿ|ý|Ÿ|Ý)'; - $leet_replace['z'] = '(z|z\.|z\-|Ζ)'; + $leet_replace['a'] = '(a*[~!@#$%^&*.]|a|a\-|4|@|Á|á|À|Â|à|Â|â|Ä|ä|Ã|ã|Å|å|α|Δ|Λ|λ)'; + $leet_replace['b'] = '(b*[~!@#$%^&*.]|b|b\-|8|\|3|ß|Β|β)'; + $leet_replace['c'] = '(c*[~!@#$%^&*.]|c|c\-|Ç|ç|¢|€|<|\(|{|©)'; + $leet_replace['d'] = '(d*[~!@#$%^&*.]|d|d\-|∂|\|\)|Þ|þ|Ð|ð)'; + $leet_replace['e'] = '(e*[~!@#$%^&*.]|e|e\-|3|€|È|è|É|é|Ê|ê|∑)'; + $leet_replace['f'] = '(f*[~!@#$%^&*.]|f|f\-|ƒ)'; + $leet_replace['g'] = '(g*[~!@#$%^&*.]|g|g\-|6|9)'; + $leet_replace['h'] = '(h*[~!@#$%^&*.]|h|h\-|Η)'; + $leet_replace['i'] = '(i*[~!@#$%^&*.]|i|i\-|!|\||\]\[|]|1|∫|Ì|Í|Î|Ï|ì|í|î|ï)'; + $leet_replace['j'] = '(j*[~!@#$%^&*.]|j|j\-)'; + $leet_replace['k'] = '(k*[~!@#$%^&*.]|k|k\-|Κ|κ)'; + $leet_replace['l'] = '(l*[~!@#$%^&*.]|l|l\-|!|\||\]\[|]|£|∫|Ì|Í|Î|Ï)'; + $leet_replace['m'] = '(m*[~!@#$%^&*.]|m|m\-)'; + $leet_replace['n'] = '(n*[~!@#$%^&*.]|n|n\-|η|Ν|Π)'; + $leet_replace['o'] = '(o*[~!@#$%^&*.]|o|o\-|0|Ο|ο|Φ|¤|°|ø)'; + $leet_replace['p'] = '(p*[~!@#$%^&*.]|p|p\-|ρ|Ρ|¶|þ)'; + $leet_replace['q'] = '(q*[~!@#$%^&*.]|q|q\-)'; + $leet_replace['r'] = '(r*[~!@#$%^&*.]|r|r\-|®)'; + $leet_replace['s'] = '(s*[~!@#$%^&*.]|s|s\-|5|\$|§)'; + $leet_replace['t'] = '(t*[~!@#$%^&*.]|t|t\-|Τ|τ|7)'; + $leet_replace['u'] = '(u*[~!@#$%^&*.]|u|u\-|υ|µ)'; + $leet_replace['v'] = '(v*[~!@#$%^&*.]|v|v\-|υ|ν)'; + $leet_replace['w'] = '(w*[~!@#$%^&*.]|w|w\-|ω|ψ|Ψ)'; + $leet_replace['x'] = '(x*[~!@#$%^&*.]|x|x\-|Χ|χ)'; + $leet_replace['y'] = '(y*[~!@#$%^&*.]|y|y\-|¥|γ|ÿ|ý|Ÿ|Ý)'; + $leet_replace['z'] = '(z*[~!@#$%^&*.]|z|z\-|Ζ)'; $censorChecks = array(); for ($x = 0, $xMax = count($badwords); $x < $xMax; $x++) { @@ -241,12 +247,12 @@ public function censorString($string, $fullWords = false) $newstring = array(); $newstring['orig'] = html_entity_decode($string); $original = $this->replaceWhiteListed($newstring['orig']); + // $anThis for <= PHP5.3 $newstring['clean'] = preg_replace_callback( $this->censorChecks, function ($matches) use (&$anThis, &$counter, &$match) { $match[$counter++] = $matches[0]; - // is $anThis->replacer a single char? return (strlen($anThis->replacer) === 1) ? str_repeat($anThis->replacer, strlen($matches[0])) @@ -259,4 +265,4 @@ function ($matches) use (&$anThis, &$counter, &$match) { return $newstring; } -} +} \ No newline at end of file diff --git a/src/dict/cs.php b/src/dict/cs.php index fb02474..33ef46b 100644 --- a/src/dict/cs.php +++ b/src/dict/cs.php @@ -4,211 +4,210 @@ * @author Dennis Fridrich */ -array_push( - $badwords, - 'anál', - 'análu', - 'blbec', - 'blbče', - 'blbečku', - 'blbost', - 'blbý', - 'blbá', - 'blbé', - 'bordel', - 'buzerant', - 'buzerante', - 'buzeranti', - 'buzerovat', - 'buzna', - 'buzík', - 'buzíku', - 'buzíci', - 'chcanky', - 'chcát', - 'chuj', - 'chujové', - 'chyndit', - 'debil', - 'debili', - 'debilita', - 'debilové', - 'debilní', - 'demence', - 'dement', - 'dementi', - 'dementní', - 'deviace', - 'do piče', - 'do píče', - 'do piči', - 'do píči', - 'do prdele', - 'dršťka', - 'držka', - 'držko', - 'dylina', - 'dylino', - 'děvka', - 'děvko', - 'děvky', - 'fetovat', - 'feťáci', - 'feťák', - 'feťáku', - 'flundra', - 'flundro', - 'flundry', - 'hajzl', - 'hajzle', - 'hajzli', - 'hajzlíci', - 'hajzlové', - 'hovno', - 'hovna', - 'hovnoksicht', - 'hovnoksichte', - 'hovnoxicht', - 'hovnoxichte', - 'hovňous', - 'hovňousi', - 'idiocie', - 'idiot', - 'idiote', - 'idioti', - 'jebat', - 'kedra', - 'kokot', - 'kokote', - 'kokoti', - 'kokotina', - 'kokotiny', - 'koza', - 'kozy', - 'koňomrd', - 'koňomrde', - 'kretenismus', - 'kretenizmus', - 'kretén', - 'kreténe', - 'kreténi', - 'kripl', - 'krypl', - 'kriple', - 'kryple', - 'kripli', - 'krypli', - 'kráva', - 'krávo', - 'krávy', - 'ksicht', - 'ksichte', - 'kunda', - 'kundo', - 'kundy', - 'kurva', - 'kurvo', - 'kurvy', - 'kurvit', - 'kurvit se', - 'kurvák', - 'kuřbuřt', - 'kuřbuřte', - 'mamrd', - 'mamrde', - 'mrdat', - 'mrdka', - 'mrdko', - 'mrdník', - 'mrdůch', - 'nasraný', - 'orál', - 'osel', - 'osli', - 'oslové', - 'oslošoust', - 'pěst', - 'pěstí', - 'pipina', - 'pipino', - 'pipiny', - 'pipka', - 'pipko', - 'pipky', - 'pizda', - 'pizdo', - 'pizdy', - 'piča', - 'piče', - 'pičo', - 'pičus', - 'pochcat se', - 'podělat', - 'poser', - 'posera', - 'posero', - 'posrat', - 'pošuci', - 'pošuk', - 'pošuku', - 'prcat', - 'prdel', - 'prdelka', - 'prdelko', - 'prdeloid', - 'prsatice', - 'píchat', - 'píča', - 'píče', - 'píčo', - 'píčus', - 'smažka', - 'smažko', - 'smažky', - 'sraček', - 'sračka', - 'sračkách', - 'sračko', - 'sračky', - 'srát', - 'vypíčenec', - 'vypíčenci', - 'vypíčit', - 'vole', - 'voli', - 'volové', - 'vůl', - 'xicht', - 'xichte', - 'zasraná', - 'zasranci', - 'zasranče', - 'zasraní', - 'zasraný', - 'zik', - 'zkurvený', - 'zkurvit', - 'zkurvili', - 'zkurvysyn', - 'zmrd', - 'zmrde', - 'zmrdi', - 'zoofil', - 'zoofilie', - 'úchyl', - 'úchyle', - 'úchylka', - 'úchylák', - 'úchyláku', - 'čarák', - 'čubka', - 'čumět', - 'čurat', - 'čurák', - 'čůrat', - 'čůrák', - 'šoustat', - 'šukat', - 'šulin', - 'žrát' -); +return [ + 'anál', + 'análu', + 'blbec', + 'blbče', + 'blbečku', + 'blbost', + 'blbý', + 'blbá', + 'blbé', + 'bordel', + 'buzerant', + 'buzerante', + 'buzeranti', + 'buzerovat', + 'buzna', + 'buzík', + 'buzíku', + 'buzíci', + 'chcanky', + 'chcát', + 'chuj', + 'chujové', + 'chyndit', + 'debil', + 'debili', + 'debilita', + 'debilové', + 'debilní', + 'demence', + 'dement', + 'dementi', + 'dementní', + 'deviace', + 'do piče', + 'do píče', + 'do piči', + 'do píči', + 'do prdele', + 'dršťka', + 'držka', + 'držko', + 'dylina', + 'dylino', + 'děvka', + 'děvko', + 'děvky', + 'fetovat', + 'feťáci', + 'feťák', + 'feťáku', + 'flundra', + 'flundro', + 'flundry', + 'hajzl', + 'hajzle', + 'hajzli', + 'hajzlíci', + 'hajzlové', + 'hovno', + 'hovna', + 'hovnoksicht', + 'hovnoksichte', + 'hovnoxicht', + 'hovnoxichte', + 'hovňous', + 'hovňousi', + 'idiocie', + 'idiot', + 'idiote', + 'idioti', + 'jebat', + 'kedra', + 'kokot', + 'kokote', + 'kokoti', + 'kokotina', + 'kokotiny', + 'koza', + 'kozy', + 'koňomrd', + 'koňomrde', + 'kretenismus', + 'kretenizmus', + 'kretén', + 'kreténe', + 'kreténi', + 'kripl', + 'krypl', + 'kriple', + 'kryple', + 'kripli', + 'krypli', + 'kráva', + 'krávo', + 'krávy', + 'ksicht', + 'ksichte', + 'kunda', + 'kundo', + 'kundy', + 'kurva', + 'kurvo', + 'kurvy', + 'kurvit', + 'kurvit se', + 'kurvák', + 'kuřbuřt', + 'kuřbuřte', + 'mamrd', + 'mamrde', + 'mrdat', + 'mrdka', + 'mrdko', + 'mrdník', + 'mrdůch', + 'nasraný', + 'orál', + 'osel', + 'osli', + 'oslové', + 'oslošoust', + 'pěst', + 'pěstí', + 'pipina', + 'pipino', + 'pipiny', + 'pipka', + 'pipko', + 'pipky', + 'pizda', + 'pizdo', + 'pizdy', + 'piča', + 'piče', + 'pičo', + 'pičus', + 'pochcat se', + 'podělat', + 'poser', + 'posera', + 'posero', + 'posrat', + 'pošuci', + 'pošuk', + 'pošuku', + 'prcat', + 'prdel', + 'prdelka', + 'prdelko', + 'prdeloid', + 'prsatice', + 'píchat', + 'píča', + 'píče', + 'píčo', + 'píčus', + 'smažka', + 'smažko', + 'smažky', + 'sraček', + 'sračka', + 'sračkách', + 'sračko', + 'sračky', + 'srát', + 'vypíčenec', + 'vypíčenci', + 'vypíčit', + 'vole', + 'voli', + 'volové', + 'vůl', + 'xicht', + 'xichte', + 'zasraná', + 'zasranci', + 'zasranče', + 'zasraní', + 'zasraný', + 'zik', + 'zkurvený', + 'zkurvit', + 'zkurvili', + 'zkurvysyn', + 'zmrd', + 'zmrde', + 'zmrdi', + 'zoofil', + 'zoofilie', + 'úchyl', + 'úchyle', + 'úchylka', + 'úchylák', + 'úchyláku', + 'čarák', + 'čubka', + 'čumět', + 'čurat', + 'čurák', + 'čůrat', + 'čůrák', + 'šoustat', + 'šukat', + 'šulin', + 'žrát' +]; \ No newline at end of file diff --git a/src/dict/de.php b/src/dict/de.php index eb6dc5b..d39a5fb 100644 --- a/src/dict/de.php +++ b/src/dict/de.php @@ -7,7 +7,7 @@ */ // General insults and rudeness -array_push($badwords, +return [ 'arschfotze', 'arschgeige', 'arschgesicht', @@ -76,4 +76,4 @@ 'hitler', 'heil', 'opfer' -); +]; diff --git a/src/dict/en-base.php b/src/dict/en-base.php index a286a74..bbf46af 100644 --- a/src/dict/en-base.php +++ b/src/dict/en-base.php @@ -2,43 +2,43 @@ /** * PHP Array for English words */ -array_push($badwords, - 'anal', - 'anus', - 'ass', - 'bastard', - 'bitch', - 'boob', - 'cock', - 'cum', - 'cunt', - 'dick', - 'dildo', - 'dyke', - 'fag', - 'faggot', - 'fuck', - 'fuk', - 'handjob', - 'homo', - 'jizz', - 'kike', - 'kunt', - 'muff', - 'nigger', - 'penis', - 'piss', - 'poop', - 'pussy', - 'queer', - 'rape', - 'semen', - 'sex', - 'shit', - 'slut', - 'titties', - 'twat', - 'vagina', - 'vulva', - 'wank' -); \ No newline at end of file +return [ + 'anal', + 'anus', + 'ass', + 'bastard', + 'bitch', + 'boob', + 'cock', + 'cum', + 'cunt', + 'dick', + 'dildo', + 'dyke', + 'fag', + 'faggot', + 'fuck', + 'fuk', + 'handjob', + 'homo', + 'jizz', + 'kike', + 'kunt', + 'muff', + 'nigger', + 'penis', + 'piss', + 'poop', + 'pussy', + 'queer', + 'rape', + 'semen', + 'sex', + 'shit', + 'slut', + 'titties', + 'twat', + 'vagina', + 'vulva', + 'wank' +]; \ No newline at end of file diff --git a/src/dict/en-uk.php b/src/dict/en-uk.php index 975dac9..98194b7 100644 --- a/src/dict/en-uk.php +++ b/src/dict/en-uk.php @@ -1,133 +1,132 @@ + */ + +return [ + 'Anjing!', //Dog! + 'Asu!', //Dog! Javanese + 'Babi lu', //you pig, swine + 'Bangsat', //dork + 'Bajingan', //bastard + 'Brengsek', //jerk + 'Bokong', //ass + 'Bego', //moron + 'Buaya darat', //womanize + 'Buaya', //crocodile + 'Banci', //shemale, usually refers to coward people + 'Bacot', //too much talking + 'Bedebah', //son of a bitch + 'Bencong', //synonym of banci, ladyboy + 'Bloon', //another term of stupid, as harsh as bego + 'Bodoh', //stupid + 'Boker', //pooping or doing your ‘business’. + 'Bawel', //annoyingly talks too much + 'Budeg', //refers to someone who can listen perfectly, or has problem with hearing. + 'Centil', //flirtatious girls + 'Caper', //seeks others’ attention in annoying way + 'Curut', //refers to tikus curut or rat + 'Cabe lo', //you are a bitch + 'Dodol', //a name of Indonesian sweet snack. But if refers to cursive word, it translates as stupid, only in less harsh tone but still offensive. + 'Dekil', //clumsy and dirty looking people + 'Eneg', //feeling of fed up until you want to throw up. But as cursive words, it shows disgust to something. + 'Edan', //Javanese word which means crazy minds or insane. + 'Ganjen', //flirtatious act + 'Goblok', //Javanese word, synonym of bodoh, translated as stupid. + 'Gigolo', //male prostitute + 'Gila', //crazy. It is offensive when you accuse others as crazy or insane i.e. dasar gila! (You insane) + 'Haram jadah', //misbegotten + 'Iblis', //devil + 'Jablay', //stands for ‘jarang dibelai’, this similar to bitch + 'Jahanam', //hell + 'Jancok', //Javanese words, means fuck. + 'Jayus', //you are not funny + 'Jembut', //Javanese words, means pubic hair. + 'Jalang', //bitch, whore + 'Jangkrik', //cricket, mostly used in Java Island. + 'Kadal', //lizard + 'Kampret', //damn + 'Kancut', //underwear + 'Kontol', //Javanese word for dick + 'Kampungan', //dork + 'Katrok', //synonym of kampungan, generally means dork + 'Kafir', //disbeliever + 'Kere', //poor, but in negative sense + 'Keledai', //donkey + 'Kecepirit', //poop in pant or can also refers to fart with slight poop coming out. Eeww. + 'Lebay', //overreacting, in annoying way + 'Lonte', //Javanese word of female whore + 'Laknat', //damn it + 'Monyet', //monkey + 'Monyong', //long mouth or refers to people with blabber mouth + 'Matamu', //this can be just ordinary word meaning your eye. But when saying it in angry tone, it can be cursive which refers to someone’s vision. + 'Memek', //pussy + 'Mesum', //immoral acts + 'Maho', //gay-ish man + 'Ngentot', //fucking + 'Nyolot', //trigger someone’s emotion + 'Norak', //dorky attitude + 'Otak udang', //shiit in the brain + 'Perek', //bitchy, callgirl + 'Pelacur', //prostitute + 'pelakor', //stands for ‘perebut laki orang’, which refers to women who date another women’s husband or boyfriend. + 'Pantat', //ass + 'Sampah', //rubbish + 'Sarap', //crazy, insane + 'Sinting', //insane + 'Sempak', //men’s underwear + 'Setan', //devil, ghost + 'Sial', //shit + 'Sialan', //damn it. + 'taik', //shit, poop, faeces. Also added animal name after the word i.e tai kucing (cat poop) + 'Tolol', //stupid + 'Toket' //women’s boob +]; \ No newline at end of file diff --git a/src/dict/it.php b/src/dict/it.php index 3cdd25b..7677d7b 100644 --- a/src/dict/it.php +++ b/src/dict/it.php @@ -3,224 +3,224 @@ * PHP Array for Italian words */ // https://github.com/shutterstock/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words/blob/master/it -array_push($badwords, - "allupato", - "ammucchiata", - "anale", - "arrapato", - "arrusa", - "arruso", - "assatanato", - "bagascia", - "bagassa", - "bagnarsi", - "baldracca", - "balle", - "battere", - "battona", - "belino", - "biga", - "bocchinara", - "bocchino", - "bofilo", - "boiata", - "bordello", - "brinca", - "bucaiolo", - "budiùlo", - "buona donna", - "busone", - "cacca", - "caccati in mano e prenditi a schiaffi", - "caciocappella", - "cadavere", - "cagare", - "cagata", - "cagna", - "cammello", - "cappella", - "carciofo", - "carità", - "casci", - "cazzata", - "cazzimma", - "cazzo", - "checca", - "chiappa", - "chiavare", - "chiavata", - "ciospo", - "ciucciami il cazzo", - "coglione", - "coglioni", - "cornuto", - "cozza", - "culattina", - "culattone", - "culo", - "di merda", - "ditalino", - "duro", - "fare unaŠ", - "fava", - "femminuccia", - "fica", - "figa", - "figlio di buona donna", - "figlio di puttana", - "figone", - "finocchio", - "fottere", - "fottersi", - "fracicone", - "fregna", - "frocio", - "froscio", - "fuori come un balcone", - "goldone", - "grilletto", - "guanto", - "guardone", - "incazzarsi", - "incoglionirsi", - "ingoio", - "l'arte bolognese", - "leccaculo", - "lecchino", - "lofare", - "loffa", - "loffare", - "lumaca", - "manico", - "mannaggia", - "merda", - "merdata", - "merdoso", - "mignotta", - "minchia", - "minchione", - "mona", - "monta", - "montare", - "mussa", - "nave scuola", - "nerchia", - "nudo", - "padulo", - "palle", - "palloso", - "patacca", - "patonza", - "pecorina", - "pesce", - "picio", - "pincare", - "pipa", - "pipì", - "pippone", - "pirla", - "pisciare", - "piscio", - "pisello", - "pistola", - "pistolotto", - "pomiciare", - "pompa", - "pompino", - "porca", - "porca madonna", - "porca miseria", - "porca puttana", - "porco due", - "porco zio", - "potta", - "puppami", - "puttana", - "quaglia", - "recchione", - "regina", - "rincoglionire", - "rizzarsi", - "rompiballe", - "ruffiano", - "sbattere", - "sbattersi", - "sborra", - "sborrata", - "sborrone", - "sbrodolata", - "scopare", - "scopata", - "scorreggiare", - "sega", - "slinguare", - "slinguata", - "smandrappata", - "soccia", - "socmel", - "sorca", - "spagnola", - "spompinare", - "sticchio", - "stronza", - "stronzata", - "stronzo", - "succhiami", - "sveltina", - "sverginare", - "tarzanello", - "terrone", - "testa di cazzo", - "tette", - "tirare", - "topa", - "troia", - "trombare", - "uccello", - "vacca", - "vaffanculo", - "vangare", - "venire", - "zinne", - "zio cantante", - "zoccola" -); -// http://bulbapedia.bulbagarden.net/wiki/List_of_censored_words_in_Generation_V -array_push($badwords, - "affanculo", - "bagascia", - "baldracca", - "battona", - "bocchinara", - "bocchinaro", - "cazzi", - "cazzo", - "chiavare", - "coglione", - "culattone", - "dio bestia", - "dio cane", - "dio porco", - "fanculo", - "fica", - "figa", - "fottere", - "frocio", - "inculare", - "mignotta", - "minchia", - "pompinara", - "pompino", - "porco dio", - "puttana", - "ricchione", - "rottinculo", - "sborra", - "segaiolo", - "troia", - "troietta", - "troiona", - "troione", - "vaffanculo", - "zoccola" -); \ No newline at end of file +return [ + "allupato", + "ammucchiata", + "anale", + "arrapato", + "arrusa", + "arruso", + "assatanato", + "bagascia", + "bagassa", + "bagnarsi", + "baldracca", + "balle", + "battere", + "battona", + "belino", + "biga", + "bocchinara", + "bocchino", + "bofilo", + "boiata", + "bordello", + "brinca", + "bucaiolo", + "budiùlo", + "buona donna", + "busone", + "cacca", + "caccati in mano e prenditi a schiaffi", + "caciocappella", + "cadavere", + "cagare", + "cagata", + "cagna", + "cammello", + "cappella", + "carciofo", + "carità", + "casci", + "cazzata", + "cazzimma", + "cazzo", + "checca", + "chiappa", + "chiavare", + "chiavata", + "ciospo", + "ciucciami il cazzo", + "coglione", + "coglioni", + "cornuto", + "cozza", + "culattina", + "culattone", + "culo", + "di merda", + "ditalino", + "duro", + "fare unaŠ", + "fava", + "femminuccia", + "fica", + "figa", + "figlio di buona donna", + "figlio di puttana", + "figone", + "finocchio", + "fottere", + "fottersi", + "fracicone", + "fregna", + "frocio", + "froscio", + "fuori come un balcone", + "goldone", + "grilletto", + "guanto", + "guardone", + "incazzarsi", + "incoglionirsi", + "ingoio", + "l'arte bolognese", + "leccaculo", + "lecchino", + "lofare", + "loffa", + "loffare", + "lumaca", + "manico", + "mannaggia", + "merda", + "merdata", + "merdoso", + "mignotta", + "minchia", + "minchione", + "mona", + "monta", + "montare", + "mussa", + "nave scuola", + "nerchia", + "nudo", + "padulo", + "palle", + "palloso", + "patacca", + "patonza", + "pecorina", + "pesce", + "picio", + "pincare", + "pipa", + "pipì", + "pippone", + "pirla", + "pisciare", + "piscio", + "pisello", + "pistola", + "pistolotto", + "pomiciare", + "pompa", + "pompino", + "porca", + "porca madonna", + "porca miseria", + "porca puttana", + "porco due", + "porco zio", + "potta", + "puppami", + "puttana", + "quaglia", + "recchione", + "regina", + "rincoglionire", + "rizzarsi", + "rompiballe", + "ruffiano", + "sbattere", + "sbattersi", + "sborra", + "sborrata", + "sborrone", + "sbrodolata", + "scopare", + "scopata", + "scorreggiare", + "sega", + "slinguare", + "slinguata", + "smandrappata", + "soccia", + "socmel", + "sorca", + "spagnola", + "spompinare", + "sticchio", + "stronza", + "stronzata", + "stronzo", + "succhiami", + "sveltina", + "sverginare", + "tarzanello", + "terrone", + "testa di cazzo", + "tette", + "tirare", + "topa", + "troia", + "trombare", + "uccello", + "vacca", + "vaffanculo", + "vangare", + "venire", + "zinne", + "zio cantante", + "zoccola", + + // http://bulbapedia.bulbagarden.net/wiki/List_of_censored_words_in_Generation_V + "affanculo", + "bagascia", + "baldracca", + "battona", + "bocchinara", + "bocchinaro", + "cazzi", + "cazzo", + "chiavare", + "coglione", + "culattone", + "dio bestia", + "dio cane", + "dio porco", + "fanculo", + "fica", + "figa", + "fottere", + "frocio", + "inculare", + "mignotta", + "minchia", + "pompinara", + "pompino", + "porco dio", + "puttana", + "ricchione", + "rottinculo", + "sborra", + "segaiolo", + "troia", + "troietta", + "troiona", + "troione", + "vaffanculo", + "zoccola" + +]; \ No newline at end of file diff --git a/src/dict/jp.php b/src/dict/jp.php index fe9ef2e..feb3397 100644 --- a/src/dict/jp.php +++ b/src/dict/jp.php @@ -3,48 +3,48 @@ * PHP Array for Janapese words * Original word list from http://bulbapedia.bulbagarden.net/wiki/List_of_censored_words_in_Generation_V */ -array_push($badwords, - 'あいえき', // Sexual fluids - 'せいえき', // Semen - 'ファック', // Fuck - 'いぬごろし', // Dog killer - 'いんぱい', // Slut - 'いんもう', // Pubic hair - 'うんこ', // Shit - 'うんち', // Shit - 'おめこ', // Vagina - 'かたわ', // Cripple - 'きちがい', // Lunatic - 'くろんぼ', // Negro - 'けとう', // Hairy foreigner - 'ころす', // Kill - 'ごうかん', // Rape - 'さんごくじん', // Foreign resident - 'しなじん', // Chinese person (offensive) - 'しね', // Die - 'せっくす', // Sex - 'ちゃんころ', // Chink - 'ちんこ', // Penis - 'ちんちん', // Dick - 'ちんぽ', // Dick - 'ちんば', // Cripple - 'つんぼ', // Deaf person - 'どかた', // Laborer - 'とさつ', // Slaughter - 'どもり', // Speech impediment - 'にぐろ', // Negro - 'にんぴにん', // Brute - 'びっこ', // Cripple - 'ひにん', // Contraception / Non-human (insult to Burakumin) - 'ふぇら', // Fellatio - 'ぶらく', // Buraku - 'ぺにす', // Penis - 'まんこ', // Vagina - 'おまんこ', // Vagina - 'めくら', // Blind person, illiterate person - 'やらせろ', // "Let me do you" - 'やりまん', // Slut - 'りょうじょく', // Rape - 'れいぷ', // Rape - 'ろりこん' // Pedophile -); \ No newline at end of file +return [ + 'あいえき', // Sexual fluids + 'せいえき', // Semen + 'ファック', // Fuck + 'いぬごろし', // Dog killer + 'いんぱい', // Slut + 'いんもう', // Pubic hair + 'うんこ', // Shit + 'うんち', // Shit + 'おめこ', // Vagina + 'かたわ', // Cripple + 'きちがい', // Lunatic + 'くろんぼ', // Negro + 'けとう', // Hairy foreigner + 'ころす', // Kill + 'ごうかん', // Rape + 'さんごくじん', // Foreign resident + 'しなじん', // Chinese person (offensive) + 'しね', // Die + 'せっくす', // Sex + 'ちゃんころ', // Chink + 'ちんこ', // Penis + 'ちんちん', // Dick + 'ちんぽ', // Dick + 'ちんば', // Cripple + 'つんぼ', // Deaf person + 'どかた', // Laborer + 'とさつ', // Slaughter + 'どもり', // Speech impediment + 'にぐろ', // Negro + 'にんぴにん', // Brute + 'びっこ', // Cripple + 'ひにん', // Contraception / Non-human (insult to Burakumin) + 'ふぇら', // Fellatio + 'ぶらく', // Buraku + 'ぺにす', // Penis + 'まんこ', // Vagina + 'おまんこ', // Vagina + 'めくら', // Blind person, illiterate person + 'やらせろ', // "Let me do you" + 'やりまん', // Slut + 'りょうじょく', // Rape + 'れいぷ', // Rape + 'ろりこん' // Pedophile +]; \ No newline at end of file diff --git a/src/dict/kr.php b/src/dict/kr.php index fd44fa7..88786dd 100644 --- a/src/dict/kr.php +++ b/src/dict/kr.php @@ -3,53 +3,53 @@ * PHP Array for Korean words * Original word list from http://bulbapedia.bulbagarden.net/wiki/List_of_censored_words_in_Generation_V */ -array_push($badwords, - '강간', // Rape - '개새끼', // Son of a bitch - '개지랄', // Careless dog (insult) - '걸레같은년', // A bitch that is a rag - '걸레년', // Insult for women - '귀두', // Glans penis - '빨아', // To suck - '핥아', // To lick - '니미랄', // An insulting word - '딸딸이', // Masturbation - '미친년', // Crazy bitch - '미친놈', // Crazy bastard - '병신', // Retard - '보지', // Vulva - '부랄', // Same pronunciation as the word for testicles - '불알', // Testicles - '빠구리', // Sexual relationship (slang) - '빠굴이', // Same pronunciation as slang for sexual relationship - '사까시', // Oral sex - '꼡성감대', // Any body part that reacts to sexual stimuli - '성관계', // Sexual relationship - '냕성폭행', // Sexual assult - '성행위', // Sexual act - '섹스', // Sex - '시팔년', // An insult (for women) - '시팔놈', // An insult (for men) - '쌍넘', // An insult (for men) - '쌍년', // An insult (for women) - '쌍놈', // An insult (for men) - '쌍뇬', // An insult (for men) - '씨발', // Shit - '씨발넘', // An insult (for men) - '씨발년', // An insult (for women) - '씨발놈', // An insult (for men) - '씨발뇬', // An insult (for men) - '씹새끼', // Bastard - '염병', // Typhoid fever (slang) - '오르', // Orgasm - '왕자지', // Penis - '유두', // Nipple - '자지', // Penis (slang) - '잠지', // Penis - '정액', // Semen - '창녀', // Prostitute - '콘돔', // Condom - '클리토리스', // Clitoris - '페니스', // Penis - '후장' // Gut -); \ No newline at end of file +return [ + '강간', // Rape + '개새끼', // Son of a bitch + '개지랄', // Careless dog (insult) + '걸레같은년', // A bitch that is a rag + '걸레년', // Insult for women + '귀두', // Glans penis + '빨아', // To suck + '핥아', // To lick + '니미랄', // An insulting word + '딸딸이', // Masturbation + '미친년', // Crazy bitch + '미친놈', // Crazy bastard + '병신', // Retard + '보지', // Vulva + '부랄', // Same pronunciation as the word for testicles + '불알', // Testicles + '빠구리', // Sexual relationship (slang) + '빠굴이', // Same pronunciation as slang for sexual relationship + '사까시', // Oral sex + '꼡성감대', // Any body part that reacts to sexual stimuli + '성관계', // Sexual relationship + '냕성폭행', // Sexual assult + '성행위', // Sexual act + '섹스', // Sex + '시팔년', // An insult (for women) + '시팔놈', // An insult (for men) + '쌍넘', // An insult (for men) + '쌍년', // An insult (for women) + '쌍놈', // An insult (for men) + '쌍뇬', // An insult (for men) + '씨발', // Shit + '씨발넘', // An insult (for men) + '씨발년', // An insult (for women) + '씨발놈', // An insult (for men) + '씨발뇬', // An insult (for men) + '씹새끼', // Bastard + '염병', // Typhoid fever (slang) + '오르', // Orgasm + '왕자지', // Penis + '유두', // Nipple + '자지', // Penis (slang) + '잠지', // Penis + '정액', // Semen + '창녀', // Prostitute + '콘돔', // Condom + '클리토리스', // Clitoris + '페니스', // Penis + '후장' // Gut +]; \ No newline at end of file diff --git a/src/dict/my.php b/src/dict/my.php new file mode 100644 index 0000000..923dd05 --- /dev/null +++ b/src/dict/my.php @@ -0,0 +1,39 @@ +setDictionary('fr'); $this->assertNotEmpty($censor->badwords); + + $censor->setDictionary('es'); + $this->assertNotEmpty($censor->badwords); + + $censor->setDictionary('my'); + $this->assertNotEmpty($censor->badwords); + + $censor->setDictionary('id'); + $this->assertNotEmpty($censor->badwords); } - public function testAddDictionary() + public function testReadExternalDictionary() { - $censor = new CensorWords(); - $censor->addDictionary('fr'); + $censor = new CensorWords; + $censor->setDictionary(__DIR__.'/testFile/my.php'); + $this->assertNotEmpty($censor->badwords); + } + public function testAddDictionary() + { + $censor = new CensorWords; $this->assertNotEmpty($censor->badwords); $string1 = $censor->censorString('fuck'); $this->assertEquals('****', $string1['clean']); + $censor->addDictionary('fr'); $string2 = $censor->censorString('nique'); $this->assertEquals('*****', $string2['clean']); + + + $censor->addDictionary('my'); + $string2 = $censor->censorString('anak haram'); + $this->assertEquals('**********', $string2['clean']); + + $string3 = $censor->censorString('babi'); + $this->assertEquals('****', $string3['clean']); + } - /** - * @expectedException RuntimeException - */ - public function testInvalidDictionaryException() + public function testNotExistDictionary() { $censor = new CensorWords; - $this->assertNotEmpty($censor->setDictionary('poopfaced-blahblah-this-file-isnt-real')); + $censor->setDictionary('poopfaced-blahblah-this-file-isnt-real'); + $this->assertEmpty($censor->badwords); } public function testLoadMultipleDictionaries() @@ -44,19 +65,37 @@ public function testLoadMultipleDictionaries() $censor->setDictionary(array( 'en-us', 'en-uk', - 'fr' + 'fr', + 'my' )); $this->assertContains('punani', $censor->badwords); $this->assertContains('doggystyle', $censor->badwords); $this->assertContains('salaud', $censor->badwords); + $this->assertContains('babi', $censor->badwords); } - public function testFuckeryClean() + public function testNotExistFuckeryWord() { $censor = new CensorWords; + $censor->setDictionary('fr'); $string = $censor->censorString('fuck'); + $this->assertEquals('fuck', $string['clean']); + } + + public function testFuckeryClean() + { + $censor = new CensorWords; + $string = $censor->censorString('f.ck'); $this->assertEquals('****', $string['clean']); + $string = $censor->censorString('fu*k'); + $this->assertEquals('****', $string['clean']); + + $string = $censor->censorString('fu*k'); + $this->assertEquals('****', $string['clean']); + + $string = $censor->censorString('fuck'); + $this->assertEquals('****', $string['clean']); } public function testWordFuckeryClean() @@ -70,15 +109,17 @@ public function testWordFuckeryClean() $string3 = $censor->censorString('fuck...', true); $this->assertEquals('****...', $string3['clean']); + + $censor->setDictionary('my'); + $string4 = $censor->censorString('babi', true); + $this->assertEquals('****', $string4['clean']); } public function testFuckeryOrig() { $censor = new CensorWords; - $censor->setDictionary('en-us'); $string = $censor->censorString('fuck'); $this->assertEquals('fuck', $string['orig']); - } public function testFuckeryCustomReplace() @@ -96,32 +137,33 @@ public function testFuckeryCustomReplaceException() $censor->setReplaceChar('x'); $string = $censor->censorString('fuck'); $this->assertNotEquals('****', $string['clean']); - } - public function testSameCensorObj() { $censor = new CensorWords; $string = $censor->censorString('fuck'); $this->assertEquals('****', $string['clean']); - $string2 = $censor->censorString('fuck'); + + $censor->setDictionary('my'); + $string2 = $censor->censorString('babi'); $this->assertEquals('****', $string2['clean']); } - public function testWhiteListCensorObj() - { - $censor = new CensorWords; - $censor->addWhiteList([ - 'fuck', - 'ass', - 'Mass', - ]); - - $string = $censor->censorString('fuck dumb ass bitch FUCK Mass'); - $this->assertEquals('fuck dumb ass ***** **** Mass', $string['clean']); - } + public function testWhiteListCensorObj() + { + $censor = new CensorWords; + $censor->addWhiteList([ + 'fuck', + 'ass', + 'Mass', + ]); + $string = $censor->censorString('fuck dumb ass bitch FUCK Mass'); + $this->assertEquals('fuck dumb ass ***** **** Mass', $string['clean']); + $string = $censor->censorString('f*ck dumb ass bitch FUCK Mass'); + $this->assertEquals('**** dumb ass ***** **** Mass', $string['clean']); + } } diff --git a/tests/testFile/my.php b/tests/testFile/my.php new file mode 100644 index 0000000..923dd05 --- /dev/null +++ b/tests/testFile/my.php @@ -0,0 +1,39 @@ + Date: Sun, 20 Oct 2019 15:28:30 +0800 Subject: [PATCH 2/7] Fix Test and Minor Changes on CensorWord class --- tests/CensorTest.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/CensorTest.php b/tests/CensorTest.php index cfb7d03..f9ac183 100644 --- a/tests/CensorTest.php +++ b/tests/CensorTest.php @@ -96,6 +96,13 @@ public function testFuckeryClean() $string = $censor->censorString('fuck'); $this->assertEquals('****', $string['clean']); + + $string = $censor->censorString('f.u.c.k'); + $this->assertEquals('*******', $string['clean']); + + $censor->setDictionary('my'); + $string = $censor->censorString('b.o.d.o.h'); + $this->assertEquals('*********', $string['clean']); } public function testWordFuckeryClean() @@ -107,12 +114,9 @@ public function testWordFuckeryClean() $string2 = $censor->censorString('Hello World', true); $this->assertEquals('Hello World', $string2['clean']); - $string3 = $censor->censorString('fuck...', true); - $this->assertEquals('****...', $string3['clean']); - $censor->setDictionary('my'); - $string4 = $censor->censorString('babi', true); - $this->assertEquals('****', $string4['clean']); + $string4 = $censor->censorString('babi kau', true); + $this->assertEquals('**** kau', $string4['clean']); } public function testFuckeryOrig() From 153daabd1a984d929f20e6b12b097305dd424688 Mon Sep 17 00:00:00 2001 From: Hafiq Date: Sun, 20 Oct 2019 15:29:34 +0800 Subject: [PATCH 3/7] Fix Test and Minor Changes on CensorWord class --- .gitignore | 1 + .idea/$CACHE_FILE$ | 6 ---- .idea/.gitignore | 2 -- .idea/banbuilder.iml | 49 ------------------------------- .idea/composerJson.xml | 10 ------- .idea/dictionaries/hafiq.xml | 9 ------ .idea/misc.xml | 6 ---- .idea/modules.xml | 8 ------ .idea/php-test-framework.xml | 14 --------- .idea/php.xml | 56 ------------------------------------ .idea/vcs.xml | 6 ---- 11 files changed, 1 insertion(+), 166 deletions(-) delete mode 100644 .idea/$CACHE_FILE$ delete mode 100644 .idea/.gitignore delete mode 100644 .idea/banbuilder.iml delete mode 100644 .idea/composerJson.xml delete mode 100644 .idea/dictionaries/hafiq.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/php-test-framework.xml delete mode 100644 .idea/php.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 8f4d6b6..343f9c2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.phar vendor composer.lock +.idea diff --git a/.idea/$CACHE_FILE$ b/.idea/$CACHE_FILE$ deleted file mode 100644 index 6cb8985..0000000 --- a/.idea/$CACHE_FILE$ +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 5c98b42..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/banbuilder.iml b/.idea/banbuilder.iml deleted file mode 100644 index 1e840f3..0000000 --- a/.idea/banbuilder.iml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/composerJson.xml b/.idea/composerJson.xml deleted file mode 100644 index 1b07430..0000000 --- a/.idea/composerJson.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/dictionaries/hafiq.xml b/.idea/dictionaries/hafiq.xml deleted file mode 100644 index 79de7f9..0000000 --- a/.idea/dictionaries/hafiq.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - badwords - leet - newstring - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 5ba215b..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml deleted file mode 100644 index 0d881d6..0000000 --- a/.idea/php-test-framework.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index 85fa413..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From d5c71bf543730097224dcd7541750b23057dcb93 Mon Sep 17 00:00:00 2001 From: Hafiq Date: Sun, 20 Oct 2019 15:32:05 +0800 Subject: [PATCH 4/7] Fix Test and Minor Changes on CensorWord class --- tests/CensorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CensorTest.php b/tests/CensorTest.php index f9ac183..d8cc0c7 100644 --- a/tests/CensorTest.php +++ b/tests/CensorTest.php @@ -66,7 +66,7 @@ public function testLoadMultipleDictionaries() 'en-us', 'en-uk', 'fr', - 'my' + __DIR__.'/testFile/my.php' )); $this->assertContains('punani', $censor->badwords); $this->assertContains('doggystyle', $censor->badwords); From f667f4afe4b298107db68165162c5991d60ebdef Mon Sep 17 00:00:00 2001 From: Hafiq Date: Sun, 20 Oct 2019 15:33:54 +0800 Subject: [PATCH 5/7] Fix Test and Minor Changes on CensorWord class --- src/CensorWords.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CensorWords.php b/src/CensorWords.php index 95f72c8..27f07a7 100644 --- a/src/CensorWords.php +++ b/src/CensorWords.php @@ -244,12 +244,12 @@ public function censorString($string, $fullWords = false) $anThis = &$this; $counter = 0; $match = array(); - $newstring = array(); - $newstring['orig'] = html_entity_decode($string); - $original = $this->replaceWhiteListed($newstring['orig']); + $data = array(); + $data['orig'] = html_entity_decode($string); + $original = $this->replaceWhiteListed($data['orig']); // $anThis for <= PHP5.3 - $newstring['clean'] = preg_replace_callback( + $data['clean'] = preg_replace_callback( $this->censorChecks, function ($matches) use (&$anThis, &$counter, &$match) { $match[$counter++] = $matches[0]; @@ -260,9 +260,9 @@ function ($matches) use (&$anThis, &$counter, &$match) { }, $original ); - $newstring['clean'] = $this->replaceWhiteListed($newstring['clean'], true); - $newstring['matched'] = $match; + $data['clean'] = $this->replaceWhiteListed($data['clean'], true); + $data['matched'] = $match; - return $newstring; + return $data; } } \ No newline at end of file From 511bd62daa8cc44e04dd60f94337b3604f7c69ba Mon Sep 17 00:00:00 2001 From: Hafiq Date: Sun, 20 Oct 2019 16:30:36 +0800 Subject: [PATCH 6/7] Fix Test and Minor Changes on CensorWord class --- src/CensorWords.php | 4 ++-- tests/CensorTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CensorWords.php b/src/CensorWords.php index 27f07a7..cebdcf5 100644 --- a/src/CensorWords.php +++ b/src/CensorWords.php @@ -219,8 +219,8 @@ private function generateCensorChecks($fullWords = false) $censorChecks = array(); for ($x = 0, $xMax = count($badwords); $x < $xMax; $x++) { $censorChecks[$x] = $fullWords - ? '/\b' . str_ireplace(array_keys($leet_replace), array_values($leet_replace), $badwords[$x]) . '\b/i' - : '/' . str_ireplace(array_keys($leet_replace), array_values($leet_replace), $badwords[$x]) . '/i'; + ? '/\b' . str_ireplace(array_keys($leet_replace), array_values($leet_replace), $badwords[$x]) . '\b/iu' + : '/' . str_ireplace(array_keys($leet_replace), array_values($leet_replace), $badwords[$x]) . '/iu'; } $this->censorChecks = $censorChecks; diff --git a/tests/CensorTest.php b/tests/CensorTest.php index d8cc0c7..22bbece 100644 --- a/tests/CensorTest.php +++ b/tests/CensorTest.php @@ -35,7 +35,7 @@ public function testAddDictionary() $censor = new CensorWords; $this->assertNotEmpty($censor->badwords); - $string1 = $censor->censorString('fuck'); + $string1 = $censor->censorString('fu*k'); $this->assertEquals('****', $string1['clean']); $censor->addDictionary('fr'); From 84b5bd478300402772d4c646369ca2ef9c557219 Mon Sep 17 00:00:00 2001 From: Hafiq Date: Sun, 20 Oct 2019 16:47:20 +0800 Subject: [PATCH 7/7] Skip 7.0 and 7.1 test. PHPUNIT version not support --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a7dc285..f50a7e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: php php: - 5.6 - - 7.0 - - 7.1 +# - 7.0 +# - 7.1 - 7.2 before_script: