From 3ab77c0134e578009bd0ba4bda77b912fc93f17e Mon Sep 17 00:00:00 2001 From: kotas Date: Tue, 20 Jun 2017 10:02:49 +0200 Subject: [PATCH 1/3] Remove accent from text --- src/ProfaneValidator.php | 5 ++++- src/Str.php | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/ProfaneValidator.php b/src/ProfaneValidator.php index 78c9bdc..769884f 100644 --- a/src/ProfaneValidator.php +++ b/src/ProfaneValidator.php @@ -43,7 +43,10 @@ class ProfaneValidator */ public function isProfane($text) { - return Str::containsCaseless($text, $this->badwords); + return Str::containsCaseless( + Str::removeAccent($text), + $this->badwords + ); } public function getBadwords() diff --git a/src/Str.php b/src/Str.php index aa974f9..fdf3e65 100644 --- a/src/Str.php +++ b/src/Str.php @@ -22,4 +22,52 @@ class Str } return false; } + + public static function removeAccent($string) + { + $replace = [ + 'ъ'=>'-', 'Ь'=>'-', 'Ъ'=>'-', 'ь'=>'-', + 'Ă'=>'A', 'Ą'=>'A', 'À'=>'A', 'Ã'=>'A', 'Á'=>'A', 'Æ'=>'A', 'Â'=>'A', 'Å'=>'A', 'Ä'=>'Ae', + 'Þ'=>'B', + 'Ć'=>'C', 'ץ'=>'C', 'Ç'=>'C', + 'È'=>'E', 'Ę'=>'E', 'É'=>'E', 'Ë'=>'E', 'Ê'=>'E', + 'Ğ'=>'G', + 'İ'=>'I', 'Ï'=>'I', 'Î'=>'I', 'Í'=>'I', 'Ì'=>'I', + 'Ł'=>'L', + 'Ñ'=>'N', 'Ń'=>'N', + 'Ø'=>'O', 'Ó'=>'O', 'Ò'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'Oe', + 'Ş'=>'S', 'Ś'=>'S', 'Ș'=>'S', 'Š'=>'S', + 'Ț'=>'T', + 'Ù'=>'U', 'Û'=>'U', 'Ú'=>'U', 'Ü'=>'Ue', + 'Ý'=>'Y', + 'Ź'=>'Z', 'Ž'=>'Z', 'Ż'=>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'ŗ'=>'r', 'Ŗ'=>'r', 'ר'=>'r', 'Ŕ'=>'r', 'Р'=>'r', 'р'=>'r', + 'ș'=>'s', 'с'=>'s', 'Ŝ'=>'s', 'š'=>'s', 'ś'=>'s', 'ס'=>'s', 'ş'=>'s', 'С'=>'s', 'ŝ'=>'s', 'Щ'=>'sch', 'щ'=>'sch', 'ш'=>'sh', 'Ш'=>'sh', 'ß'=>'ss', + 'т'=>'t', 'ט'=>'t', 'ŧ'=>'t', 'ת'=>'t', 'ť'=>'t', 'ţ'=>'t', 'Ţ'=>'t', 'Т'=>'t', 'ț'=>'t', 'Ŧ'=>'t', 'Ť'=>'t', '™'=>'tm', + 'ū'=>'u', 'у'=>'u', 'Ũ'=>'u', 'ũ'=>'u', 'Ư'=>'u', 'ư'=>'u', 'Ū'=>'u', 'Ǔ'=>'u', 'ų'=>'u', 'Ų'=>'u', 'ŭ'=>'u', 'Ŭ'=>'u', 'Ů'=>'u', 'ů'=>'u', 'ű'=>'u', 'Ű'=>'u', 'Ǖ'=>'u', 'ǔ'=>'u', 'Ǜ'=>'u', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'У'=>'u', 'ǚ'=>'u', 'ǜ'=>'u', 'Ǚ'=>'u', 'Ǘ'=>'u', 'ǖ'=>'u', 'ǘ'=>'u', 'ü'=>'ue', + 'в'=>'v', 'ו'=>'v', 'В'=>'v', + 'ש'=>'w', 'ŵ'=>'w', 'Ŵ'=>'w', + 'ы'=>'y', 'ŷ'=>'y', 'ý'=>'y', 'ÿ'=>'y', 'Ÿ'=>'y', 'Ŷ'=>'y', + 'Ы'=>'y', 'ž'=>'z', 'З'=>'z', 'з'=>'z', 'ź'=>'z', 'ז'=>'z', 'ż'=>'z', 'ſ'=>'z', 'Ж'=>'zh', 'ж'=>'zh' + ]; + + return strtr($string, $replace); + } } From 645bbee51f869f558e17ecd6e164726a5f5d3255 Mon Sep 17 00:00:00 2001 From: kotas Date: Tue, 20 Jun 2017 10:03:06 +0200 Subject: [PATCH 2/3] Add slovak list of bad words --- src/dict/sk.php | 53 ++++++++++++++++++++++++++++++++++++++ src/lang/sk/validation.php | 5 ++++ 2 files changed, 58 insertions(+) create mode 100644 src/dict/sk.php create mode 100644 src/lang/sk/validation.php diff --git a/src/dict/sk.php b/src/dict/sk.php new file mode 100644 index 0000000..8a325ba --- /dev/null +++ b/src/dict/sk.php @@ -0,0 +1,53 @@ + ':attribute obsahuje vulgárny obsah' +]; From f622dec4e52f1c0dfb6bf215710886ffaf8d8570 Mon Sep 17 00:00:00 2001 From: kotas Date: Tue, 20 Jun 2017 10:03:45 +0200 Subject: [PATCH 3/3] Add test to validate word with accent --- tests/ProfaneValidatorTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/ProfaneValidatorTest.php b/tests/ProfaneValidatorTest.php index d93a3b2..9b714b9 100644 --- a/tests/ProfaneValidatorTest.php +++ b/tests/ProfaneValidatorTest.php @@ -124,6 +124,18 @@ class ProfaneValidatorTest extends PHPUnit_Framework_TestCase $this->assertEquals($profane->getBadwords(), $expected); } + public function test_can_validate_a_bad_word_with_accent() + { + $this->mockConfigs(); + + $profane = new ProfaneValidator(); + $profane->setDictionary('sk'); + + $word = "piča"; + + $this->assertTrue( $profane->isProfane($word) ); + } + private function mockConfigs() { Config::shouldReceive('get')