Compare commits
11 Commits
f55f370675
...
a49390e437
| Author | SHA1 | Date |
|---|---|---|
|
|
a49390e437 | |
|
|
a1b6412b9a | |
|
|
a3f24dccb4 | |
|
|
71ec6a8876 | |
|
|
03eb1459ee | |
|
|
0b325d6f62 | |
|
|
ba2b808b36 | |
|
|
8a41077665 | |
|
|
99f56b9aca | |
|
|
83d77d3382 | |
|
|
8341d39e46 |
|
|
@ -1 +0,0 @@
|
|||
C:37:"PHPUnit\Runner\DefaultTestResultCache":1921:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:22:{s:67:"LaravelProfaneTests\DictionaryTest::test_words_from_only_one_locale";d:0.006;s:65:"LaravelProfaneTests\DictionaryTest::test_words_from_only_one_file";d:0;s:64:"LaravelProfaneTests\DictionaryTest::test_words_from_locale_array";d:0;s:62:"LaravelProfaneTests\DictionaryTest::test_words_from_file_array";d:0;s:79:"LaravelProfaneTests\ProfaneValidatorTest::test_can_validate_a_word_with_numbers";d:0.001;s:66:"LaravelProfaneTests\ProfaneValidatorTest::test_can_validate_a_text";d:0.001;s:79:"LaravelProfaneTests\ProfaneValidatorTest::test_can_evaluate_profanity_of_a_word";d:0;s:83:"LaravelProfaneTests\ProfaneValidatorTest::test_can_evaluate_profanity_of_a_sentence";d:0;s:86:"LaravelProfaneTests\ProfaneValidatorTest::test_can_evaluate_profanity_of_a_html_string";d:0;s:76:"LaravelProfaneTests\ProfaneValidatorTest::test_can_evaluate_as_caseless_mode";d:0;s:63:"LaravelProfaneTests\ProfaneValidatorTest::test_match_exact_word";d:0;s:82:"LaravelProfaneTests\ProfaneValidatorTest::test_can_validate_a_bad_word_with_accent";d:0;s:75:"LaravelProfaneTests\ProfaneValidatorTest::test_enie_in_spanish_is_evaluated";d:0;s:75:"LaravelProfaneTests\ProfaneValidatorTest::test_can_validate_a_word_in_greek";d:0.001;s:75:"LaravelProfaneTests\ProfaneValidatorTest::test_can_validate_a_text_in_greek";d:0;s:85:"LaravelProfaneTests\StrTest::test_string_contains_a_piece_insensitive_match_from_text";d:0;s:76:"LaravelProfaneTests\StrTest::test_text_contains_insensitive_match_from_array";d:0;s:77:"LaravelProfaneTests\StrTest::test_text_contains_insensitive_match_from_string";d:0;s:86:"LaravelProfaneTests\StrTest::test_text_contains_the_same_insensitive_match_from_string";d:0;s:64:"LaravelProfaneTests\StrTest::test_remove_accents_in_spanish_text";d:0;s:54:"LaravelProfaneTests\StrTest::test_enie_char_is_allowed";d:0;s:57:"LaravelProfaneTests\StrTest::test_remove_accents_in_greek";d:0;}}}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 8.0
|
||||
- 7.4
|
||||
- 7.3
|
||||
- 7.2
|
||||
|
|
|
|||
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
|||
The MIT License
|
||||
|
||||
Copyright (c) 2016-2017 Arandi López <arandilopez.93@gmail.com>
|
||||
Copyright (c) 2016-2021 Arandi López <arandilopez.93@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
32
README.md
32
README.md
|
|
@ -13,11 +13,13 @@ I made this package to perform a validation for swearwords using Laravel validat
|
|||
## Installation
|
||||
|
||||
Install via composer
|
||||
|
||||
```shell
|
||||
composer require arandilopez/laravel-profane
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Add the `ProfaneServiceProvider` class in your `config/app.php` file.
|
||||
|
||||
```php
|
||||
|
|
@ -98,10 +100,34 @@ class MyController extends Controller
|
|||
}
|
||||
```
|
||||
|
||||
#### Strict validation
|
||||
|
||||
Now you can strictly validate the exact profane word in the content.
|
||||
|
||||
```php
|
||||
<?php
|
||||
// ...
|
||||
class MyController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'username' => 'required|strictly_profane:es,en'
|
||||
]);
|
||||
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This fixes known issues when you get a error in validation for words like `class` or `analysis`, as they include `ass` and `anal` respectively, but fails the validation for content like `sucker69`.
|
||||
|
||||
## Getting Help
|
||||
|
||||
If you're stuck getting something to work, or need to report a bug, please [post an issue in the Github Issues for this project](https://github.com/arandilopez/laravel-profane/issues).
|
||||
|
||||
## Contributing
|
||||
|
||||
If you're interesting in contributing code to this project, clone it by running:
|
||||
|
||||
```shell
|
||||
|
|
@ -112,13 +138,14 @@ Please read the [CONTRIBUTING](CONTRIBUTING.md) file.
|
|||
|
||||
Pull requests are welcome, but please make sure you provide unit tests to cover your changes. **You can help to add and support more locales!**
|
||||
|
||||
*Thanks to [@dorianneto](https://github.com/dorianneto) for his contributions.*
|
||||
_Thanks to [@dorianneto](https://github.com/dorianneto) for his contributions._
|
||||
|
||||
### Supported Locales
|
||||
|
||||
- English ( provided by [@arandilopez](https://github.com/arandilopez) )
|
||||
- Spanish ( provided by [@arandilopez](https://github.com/arandilopez) and [@xDidier901](https://github.com/xDidier901))
|
||||
- Italian ( provided by [@aletundo](https://github.com/aletundo) )
|
||||
- Brazilian Portuguese ( provided by [@ianrodriguesbr](https://github.com/ianrodriguesbr) )
|
||||
- Brazilian Portuguese ( provided by [@ianrodriguesbr](https://github.com/ianrodriguesbr) and [@LeonardoTeixeira](https://github.com/LeonardoTeixeira))
|
||||
- Traditional Chinese ( provided by [@Nationalcat](https://github.com/Nationalcat) )
|
||||
- Slovak ( provided by [@kotass](https://github.com/kotass) )
|
||||
- Dutch (Netherlands) ( provided by [@Cannonb4ll](https://github.com/Cannonb4ll) and [@WouterVanmulken](https://github.com/WouterVanmulken))
|
||||
|
|
@ -131,4 +158,5 @@ Pull requests are welcome, but please make sure you provide unit tests to cover
|
|||
- Indonesian ( provided by [@rizasaputra](https://github.com/rizasaputra) )
|
||||
|
||||
## License
|
||||
|
||||
This project is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
|
||||
|
|
|
|||
|
|
@ -16,15 +16,18 @@ class ProfaneServiceProvider extends ServiceProvider
|
|||
__DIR__.'/lang' => resource_path('lang/vendor/laravel-profane'),
|
||||
]);
|
||||
|
||||
// Rule for caseless content matching
|
||||
Validator::extend('profane', 'LaravelProfane\ProfaneValidator@validate', Lang::get('laravel-profane::validation.profane'));
|
||||
|
||||
Validator::replacer('profane', function ($message, $attribute, $rule, $parameters) {
|
||||
Validator::replacer('profane', function ($message, $attribute) {
|
||||
return str_replace(':attribute', $attribute, $message);
|
||||
});
|
||||
|
||||
// Rule for caseless but strict word matching
|
||||
Validator::extend('strictly_profane', 'LaravelProfane\ProfaneValidator@validateStrict', Lang::get('laravel-profane::validation.profane'));
|
||||
|
||||
Validator::replacer('strictly_profane', function ($message, $attribute) {
|
||||
return str_replace(':attribute', $attribute, $message);
|
||||
});
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
// code...
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,27 +2,19 @@
|
|||
|
||||
namespace LaravelProfane;
|
||||
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
|
||||
class ProfaneValidator
|
||||
{
|
||||
/**
|
||||
* [$dictionary description].
|
||||
*
|
||||
* @var [type]
|
||||
* @var Dictionary
|
||||
*/
|
||||
protected $dictionary;
|
||||
|
||||
/**
|
||||
* [$badwords description].
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $badwords = [];
|
||||
|
||||
/**
|
||||
* [__construct description].
|
||||
*
|
||||
* @param Dictionary $dictionary [description]
|
||||
*/
|
||||
public function __construct(Dictionary $dictionary)
|
||||
|
|
@ -32,25 +24,41 @@ class ProfaneValidator
|
|||
}
|
||||
|
||||
/**
|
||||
* Method to extends to Validator.
|
||||
* Method to extends to Validation Service.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param midex $value
|
||||
* @param array $parameters
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator [description]
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate($attribute, $value, $parameters)
|
||||
{
|
||||
if ($parameters) {
|
||||
$this->dictionary->setDictionary($parameters);
|
||||
$this->badwords = $this->dictionary->getDictionary();
|
||||
$this->setDictionary($parameters);
|
||||
}
|
||||
|
||||
return !$this->isProfane($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to extends to Validation Service for strict word matching.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateStrict($attribute, $value, $parameters)
|
||||
{
|
||||
if ($parameters) {
|
||||
$this->setDictionary($parameters);
|
||||
}
|
||||
|
||||
return !$this->isProfane($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check profanity of text.
|
||||
*
|
||||
|
|
@ -58,11 +66,23 @@ class ProfaneValidator
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isProfane($text)
|
||||
public function isProfane($text, $strict = false)
|
||||
{
|
||||
return Str::containsCaseless(
|
||||
Str::removeAccent($text),
|
||||
$this->badwords
|
||||
$this->sanitizeText($text),
|
||||
$this->badwords,
|
||||
$strict
|
||||
);
|
||||
}
|
||||
|
||||
private function setDictionary($dictionaries)
|
||||
{
|
||||
$this->dictionary->setDictionary($dictionaries);
|
||||
$this->badwords = $this->dictionary->getDictionary();
|
||||
}
|
||||
|
||||
private function sanitizeText($text)
|
||||
{
|
||||
return Str::removeAccent(strip_tags($text));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
87
src/Str.php
87
src/Str.php
|
|
@ -13,11 +13,12 @@ class Str
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function containsCaseless($haystack, $needles)
|
||||
public static function containsCaseless($haystack, $needles, $strict = false)
|
||||
{
|
||||
foreach ((array) $needles as $needle) {
|
||||
$needle = preg_quote($needle);
|
||||
if ($needle != '' && preg_match("/$needle/iu", $haystack)) {
|
||||
$regex = $strict ? "/\b$needle\b/iu" : "/$needle/iu";
|
||||
if ($needle != '' && preg_match($regex, $haystack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,48 +36,48 @@ class Str
|
|||
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', 'Ż'=>'Z',
|
||||
'â'=> 'a', 'ǎ'=>'a', 'ą'=>'a', 'á'=>'a', 'ă'=>'a', 'ã'=>'a', 'Ǎ'=>'a', 'а'=>'a', 'А'=>'a', 'å'=>'a', 'à'=>'a', 'א'=>'a', 'Ǻ'=>'a', 'Ā'=>'a', 'ǻ'=>'a', 'ā'=>'a', 'ä'=>'ae', 'æ'=>'ae', 'Ǽ'=>'ae', 'ǽ'=>'ae',
|
||||
'б'=> 'b', 'ב'=>'b', 'Б'=>'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', 'ĵ'=>'j', 'я'=>'ja', 'Я'=>'ja', 'Э'=>'je', 'э'=>'je', 'ё'=>'jo', 'Ё'=>'jo', 'ю'=>'ju', 'Ю'=>'ju',
|
||||
'ĸ'=> 'k', 'כ'=>'k', 'Ķ'=>'k', 'К'=>'k', 'к'=>'k', 'ķ'=>'k', 'ך'=>'k',
|
||||
'Ŀ'=> 'l', 'ŀ'=>'l', 'Л'=>'l', 'ł'=>'l', 'ļ'=>'l', 'ĺ'=>'l', 'Ĺ'=>'l', 'Ļ'=>'l', 'л'=>'l', 'Ľ'=>'l', 'ľ'=>'l', 'ל'=>'l',
|
||||
'מ'=> 'm', 'М'=>'m', 'ם'=>'m', 'м'=>'m',
|
||||
'ъ' => '-', 'Ь' => '-', 'Ъ' => '-', 'ь' => '-',
|
||||
'Ă' => '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', 'Ż' => 'Z',
|
||||
'â' => 'a', 'ǎ' => 'a', 'ą' => 'a', 'á' => 'a', 'ă' => 'a', 'ã' => 'a', 'Ǎ' => 'a', 'а' => 'a', 'А' => 'a', 'å' => 'a', 'à' => 'a', 'א' => 'a', 'Ǻ' => 'a', 'Ā' => 'a', 'ǻ' => 'a', 'ā' => 'a', 'ä' => 'ae', 'æ' => 'ae', 'Ǽ' => 'ae', 'ǽ' => 'ae',
|
||||
'б' => 'b', 'ב' => 'b', 'Б' => 'b', 'þ' => 'b',
|
||||
'ĉ' => 'c', 'Ĉ' => 'c', 'Ċ' => 'c', 'ć' => 'c', 'ç' => 'c', 'ц' => 'c', 'צ' => 'c', 'ċ' => 'c', 'Ц' => 'c', 'Č' => 'c', 'č' => 'c', 'Ч' => 'ch', 'ч' => 'ch',
|
||||
'ד' => 'd', 'ď' => 'd', 'Đ' => 'd', 'Ď' => 'd', 'đ' => 'd', 'д' => 'd', 'Д' => 'D', 'ð' => 'd',
|
||||
'є' => 'e', 'ע' => 'e', 'е' => 'e', 'Е' => 'e', 'Ə' => 'e', 'ę' => 'e', 'ĕ' => 'e', 'ē' => 'e', 'Ē' => 'e', 'Ė' => 'e', 'ė' => 'e', 'ě' => 'e', 'Ě' => 'e', 'Є' => 'e', 'Ĕ' => 'e', 'ê' => 'e', 'ə' => 'e', 'è' => 'e', 'ë' => 'e', 'é' => 'e',
|
||||
'ф' => 'f', 'ƒ' => 'f', 'Ф' => 'f',
|
||||
'ġ' => 'g', 'Ģ' => 'g', 'Ġ' => 'g', 'Ĝ' => 'g', 'Г' => 'g', 'г' => 'g', 'ĝ' => 'g', 'ğ' => 'g', 'ג' => 'g', 'Ґ' => 'g', 'ґ' => 'g', 'ģ' => 'g',
|
||||
'ח' => 'h', 'ħ' => 'h', 'Х' => 'h', 'Ħ' => 'h', 'Ĥ' => 'h', 'ĥ' => 'h', 'х' => 'h', 'ה' => 'h',
|
||||
'î' => 'i', 'ï' => 'i', 'í' => 'i', 'ì' => 'i', 'į' => 'i', 'ĭ' => 'i', 'ı' => 'i', 'Ĭ' => 'i', 'И' => 'i', 'ĩ' => 'i', 'ǐ' => 'i', 'Ĩ' => 'i', 'Ǐ' => 'i', 'и' => 'i', 'Į' => 'i', 'י' => 'i', 'Ї' => 'i', 'Ī' => 'i', 'І' => 'i', 'ї' => 'i', 'і' => 'i', 'ī' => 'i', 'ij' => 'ij', 'IJ' => 'ij',
|
||||
'й' => 'j', 'Й' => 'j', 'Ĵ' => 'j', 'ĵ' => 'j', 'я' => 'ja', 'Я' => 'ja', 'Э' => 'je', 'э' => 'je', 'ё' => 'jo', 'Ё' => 'jo', 'ю' => 'ju', 'Ю' => 'ju',
|
||||
'ĸ' => 'k', 'כ' => 'k', 'Ķ' => 'k', 'К' => 'k', 'к' => 'k', 'ķ' => 'k', 'ך' => 'k',
|
||||
'Ŀ' => 'l', 'ŀ' => 'l', 'Л' => 'l', 'ł' => 'l', 'ļ' => 'l', 'ĺ' => 'l', 'Ĺ' => 'l', 'Ļ' => 'l', 'л' => 'l', 'Ľ' => 'l', 'ľ' => 'l', 'ל' => 'l',
|
||||
'מ' => 'm', 'М' => 'm', 'ם' => 'm', 'м' => 'm',
|
||||
// 'ñ'=>'n', // for spanish cono != coño
|
||||
'н'=> 'n', 'Ņ'=>'n', 'ן'=>'n', 'ŋ'=>'n', 'נ'=>'n', 'Н'=>'n', 'ń'=>'n',
|
||||
'Ŋ'=> 'n', 'ņ'=>'n', 'ʼn'=>'n', 'Ň'=>'n', 'ň'=>'n',
|
||||
'о'=> 'o', 'О'=>'o', 'ő'=>'o', 'õ'=>'o', 'ô'=>'o', 'Ő'=>'o', 'ŏ'=>'o', 'Ŏ'=>'o', 'Ō'=>'o', 'ō'=>'o', 'ø'=>'o', 'ǿ'=>'o', 'ǒ'=>'o', 'ò'=>'o', 'Ǿ'=>'o', 'Ǒ'=>'o', 'ơ'=>'o', 'ó'=>'o', 'Ơ'=>'o', 'œ'=>'oe', 'Œ'=>'oe', 'ö'=>'oe',
|
||||
'פ'=> 'p', 'ף'=>'p', 'п'=>'p', 'П'=>'p',
|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 'ε', 'ή' => 'η', 'ί' => 'ι', 'ό' => 'ο', 'ύ' => 'υ', 'ώ' => 'ω',
|
||||
'н' => 'n', 'Ņ' => 'n', 'ן' => 'n', 'ŋ' => 'n', 'נ' => 'n', 'Н' => 'n', 'ń' => 'n',
|
||||
'Ŋ' => 'n', 'ņ' => 'n', 'ʼn' => 'n', 'Ň' => 'n', 'ň' => 'n',
|
||||
'о' => 'o', 'О' => 'o', 'ő' => 'o', 'õ' => 'o', 'ô' => 'o', 'Ő' => 'o', 'ŏ' => 'o', 'Ŏ' => 'o', 'Ō' => 'o', 'ō' => 'o', 'ø' => 'o', 'ǿ' => 'o', 'ǒ' => 'o', 'ò' => 'o', 'Ǿ' => 'o', 'Ǒ' => 'o', 'ơ' => 'o', 'ó' => 'o', 'Ơ' => 'o', 'œ' => 'oe', 'Œ' => 'oe', 'ö' => 'oe',
|
||||
'פ' => 'p', 'ף' => 'p', 'п' => 'p', 'П' => 'p',
|
||||
'ק' => 'q',
|
||||
'ŕ' => 'r', 'ř' => 'r', 'Ř' => 'r', 'ŗ' => '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);
|
||||
|
|
|
|||
|
|
@ -3,66 +3,323 @@
|
|||
|--------------------------------------------------------------------------
|
||||
| Filter the following list when this language is used.
|
||||
|--------------------------------------------------------------------------
|
||||
| Provided by @ianrodriguesbr
|
||||
| Provided by @ianrodriguesbr and @LeonardoTeixeira
|
||||
|
|
||||
*/
|
||||
return [
|
||||
'aborto',
|
||||
'anal',
|
||||
'abestada',
|
||||
'abestado',
|
||||
'acefalo',
|
||||
'alienada',
|
||||
'alienado',
|
||||
'animal de teta',
|
||||
'anta',
|
||||
'anus',
|
||||
'arregacada',
|
||||
'arregacado',
|
||||
'arrombada',
|
||||
'arrombado',
|
||||
'babaca',
|
||||
'bacura',
|
||||
'bagos',
|
||||
'baitola',
|
||||
'baleia',
|
||||
'bebum',
|
||||
'besta',
|
||||
'biba',
|
||||
'bicha',
|
||||
'bisca',
|
||||
'bixa',
|
||||
'boazuda',
|
||||
'bobo',
|
||||
'boceta',
|
||||
'bocetao',
|
||||
'bocetuda',
|
||||
'boco',
|
||||
'boiola',
|
||||
'bolagato',
|
||||
'bolcat',
|
||||
'boquete',
|
||||
'boqueteiro',
|
||||
'bosseta',
|
||||
'bosta',
|
||||
'bostana',
|
||||
'bocal',
|
||||
'braulio',
|
||||
'brioco',
|
||||
'bronha',
|
||||
'buca',
|
||||
'buceta',
|
||||
'bucetao',
|
||||
'bucetuda',
|
||||
'bunda',
|
||||
'bundao',
|
||||
'bunduda',
|
||||
'burra',
|
||||
'burro',
|
||||
'busseta',
|
||||
'cacete',
|
||||
'cachorra',
|
||||
'cachorro',
|
||||
'cadela',
|
||||
'cadelona',
|
||||
'caga',
|
||||
'cagado',
|
||||
'cagao',
|
||||
'cagona',
|
||||
'canalha',
|
||||
'caralho',
|
||||
'chupeta',
|
||||
'cuzao',
|
||||
'casseta',
|
||||
'cassete',
|
||||
'charlatao',
|
||||
'checheca',
|
||||
'chereca',
|
||||
'chibumba',
|
||||
'chibumbo',
|
||||
'chifruda',
|
||||
'chifrudo',
|
||||
'chochota',
|
||||
'chota',
|
||||
'chupada',
|
||||
'chupado',
|
||||
'clitoris',
|
||||
'corna',
|
||||
'corno',
|
||||
'cornuda',
|
||||
'cornudo',
|
||||
'corrupta',
|
||||
'corrupto',
|
||||
'cretina',
|
||||
'cretino',
|
||||
'cu',
|
||||
'estupro',
|
||||
'culhao',
|
||||
'curalho',
|
||||
'cuzao',
|
||||
'cuzuda',
|
||||
'cuzudo',
|
||||
'debil',
|
||||
'debil mental',
|
||||
'debiloide',
|
||||
'demente',
|
||||
'demonio',
|
||||
'desgraca',
|
||||
'desgracado',
|
||||
'drogado',
|
||||
'egua',
|
||||
'embessil',
|
||||
'endemoniado',
|
||||
'energumeno',
|
||||
'escrota',
|
||||
'escroto',
|
||||
'esporrada',
|
||||
'esporrado',
|
||||
'esporro',
|
||||
'estrume',
|
||||
'estupida',
|
||||
'estupidez',
|
||||
'estupido',
|
||||
'fdp',
|
||||
'fedida',
|
||||
'fedido',
|
||||
'fedor',
|
||||
'fedorenta',
|
||||
'feia',
|
||||
'feio',
|
||||
'feiosa',
|
||||
'feioso',
|
||||
'feioza',
|
||||
'feiozo',
|
||||
'filho da puta',
|
||||
'fiofo',
|
||||
'foda',
|
||||
'foder',
|
||||
'gozar',
|
||||
'foda se',
|
||||
'foda-se',
|
||||
'fodao',
|
||||
'fodase',
|
||||
'fode',
|
||||
'fodida',
|
||||
'fodido',
|
||||
'fornica',
|
||||
'fudecao',
|
||||
'fudendo',
|
||||
'fudida',
|
||||
'fudido',
|
||||
'furada',
|
||||
'furado',
|
||||
'furnica',
|
||||
'furnicar',
|
||||
'furona',
|
||||
'furao',
|
||||
'gaiata',
|
||||
'gaiato',
|
||||
'gay',
|
||||
'grelinho',
|
||||
'grelo',
|
||||
'idiota',
|
||||
'imbecil',
|
||||
'inferno',
|
||||
'masturbacao',
|
||||
'imundo',
|
||||
'iscrota',
|
||||
'iscroto',
|
||||
'jacu',
|
||||
'jamanta',
|
||||
'jegue',
|
||||
'jumento',
|
||||
'k-tchorra',
|
||||
'karalho',
|
||||
'kct',
|
||||
'kenga',
|
||||
'ku',
|
||||
'ladra',
|
||||
'ladrao',
|
||||
'ladroeira',
|
||||
'ladrona',
|
||||
'lalau',
|
||||
'lazarento',
|
||||
'leprosa',
|
||||
'leproso',
|
||||
'lezado',
|
||||
'lesbica',
|
||||
'macaca',
|
||||
'macaco',
|
||||
'machona',
|
||||
'machorra',
|
||||
'maconheiro',
|
||||
'maldita',
|
||||
'maldito',
|
||||
'manguaca',
|
||||
'manguaça',
|
||||
'masturba',
|
||||
'meleca',
|
||||
'merda',
|
||||
'mijar',
|
||||
'orgasmo',
|
||||
'orgia',
|
||||
'meretriz',
|
||||
'mija',
|
||||
'mijada',
|
||||
'mijado',
|
||||
'mijo',
|
||||
'mocrea',
|
||||
'mocreia',
|
||||
'moleca',
|
||||
'moleque',
|
||||
'mondronga',
|
||||
'mondrongo',
|
||||
'naba',
|
||||
'nadega',
|
||||
'nariguda',
|
||||
'narigudo',
|
||||
'nhaca',
|
||||
'nojeira',
|
||||
'nojenta',
|
||||
'nojento',
|
||||
'nojo',
|
||||
'ogra',
|
||||
'ogro',
|
||||
'olhota',
|
||||
'otaria',
|
||||
'otario',
|
||||
'paca',
|
||||
'panaca',
|
||||
'paspalha',
|
||||
'paspalhao',
|
||||
'paspalho',
|
||||
'pau',
|
||||
'piroca',
|
||||
'porno',
|
||||
'porra',
|
||||
'prostituta',
|
||||
'punheta',
|
||||
'punheteiro',
|
||||
'puta',
|
||||
'putaria',
|
||||
'pau no cu',
|
||||
'peido',
|
||||
'pemba',
|
||||
'penis',
|
||||
'pentelha',
|
||||
'pentelho',
|
||||
'perequita',
|
||||
'perereca',
|
||||
'pica',
|
||||
'picao',
|
||||
'pilantra',
|
||||
'pinto pequeno',
|
||||
'piranha',
|
||||
'piroca',
|
||||
'piroco',
|
||||
'piru',
|
||||
'porra',
|
||||
'pqp',
|
||||
'prega',
|
||||
'prostibulo',
|
||||
'prostituta',
|
||||
'prostituto',
|
||||
'punheta',
|
||||
'punhetao',
|
||||
'punheteiro',
|
||||
'pustula',
|
||||
'puta',
|
||||
'puta que pariu',
|
||||
'puto',
|
||||
'puxa saco',
|
||||
'puxa-saco',
|
||||
'puxasaco',
|
||||
'penis',
|
||||
'quenga',
|
||||
'rabao',
|
||||
'rabo',
|
||||
'rabuda',
|
||||
'rabudao',
|
||||
'rabudo',
|
||||
'rabudona',
|
||||
'racha',
|
||||
'rachada',
|
||||
'rachadao',
|
||||
'rachadinha',
|
||||
'rachadinho',
|
||||
'rachado',
|
||||
'rapariga',
|
||||
'rato de esgoto',
|
||||
'retardada',
|
||||
'retardado',
|
||||
'ridicula',
|
||||
'ridiculo',
|
||||
'rola',
|
||||
'rolinha',
|
||||
'rosca',
|
||||
'sacana',
|
||||
'safada',
|
||||
'safado',
|
||||
'sapatao',
|
||||
'semen',
|
||||
'sex',
|
||||
'sexo',
|
||||
'sexy',
|
||||
'sifilis',
|
||||
'siririca',
|
||||
'semen',
|
||||
'testiculo',
|
||||
'teta',
|
||||
'traseiro',
|
||||
'tarada',
|
||||
'tarado',
|
||||
'tesao',
|
||||
'testuda',
|
||||
'tetuda',
|
||||
'tetudo',
|
||||
'tezao',
|
||||
'tezuda',
|
||||
'tezudo',
|
||||
'tnc',
|
||||
'travecao',
|
||||
'traveco',
|
||||
'trocha',
|
||||
'trolha',
|
||||
'troucha',
|
||||
'trouxa',
|
||||
'troxa',
|
||||
'vaca',
|
||||
'vadia',
|
||||
'vagabunda',
|
||||
'vagabundo',
|
||||
'vagina',
|
||||
'veada',
|
||||
'veadao',
|
||||
'veado',
|
||||
'verme',
|
||||
'viada',
|
||||
'viadao',
|
||||
'viado',
|
||||
'vibrador',
|
||||
'vulva',
|
||||
'vsf',
|
||||
'xana',
|
||||
'xaninha',
|
||||
'xavasca',
|
||||
'xerereca',
|
||||
'xexeca',
|
||||
'xibiu',
|
||||
'xibumba',
|
||||
'xochota',
|
||||
'xota',
|
||||
'xoxota',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ class ProfaneValidatorTest extends TestCase
|
|||
$this->assertFalse($builder->validate(['username', 'culero23', ['es']]));
|
||||
}
|
||||
|
||||
public function test_can_not_validate_a_word_with_numbers_in_strict_mode()
|
||||
{
|
||||
$builder = new ProfaneValidatorBuilder();
|
||||
|
||||
$this->assertTrue($builder->validate(['username', 'culero23', ['es']], true));
|
||||
}
|
||||
|
||||
public function test_can_validate_a_text()
|
||||
{
|
||||
$builder = new ProfaneValidatorBuilder();
|
||||
|
|
@ -38,6 +45,15 @@ class ProfaneValidatorTest extends TestCase
|
|||
$this->assertTrue($builder->build()->isProfane($word));
|
||||
}
|
||||
|
||||
public function test_can_evaluate_profanity_of_a_sentence_in_strict_mode()
|
||||
{
|
||||
$builder = new ProfaneValidatorBuilder();
|
||||
|
||||
$word = 'fuck you if you read this';
|
||||
|
||||
$this->assertTrue($builder->build()->isProfane($word), true);
|
||||
}
|
||||
|
||||
public function test_can_evaluate_profanity_of_a_html_string()
|
||||
{
|
||||
$builder = new ProfaneValidatorBuilder();
|
||||
|
|
@ -56,7 +72,7 @@ class ProfaneValidatorTest extends TestCase
|
|||
$this->assertTrue($builder->build()->isProfane($word));
|
||||
}
|
||||
|
||||
public function test_match_exact_word()
|
||||
public function test_match_content()
|
||||
{
|
||||
$builder = new ProfaneValidatorBuilder();
|
||||
|
||||
|
|
@ -67,6 +83,17 @@ class ProfaneValidatorTest extends TestCase
|
|||
$this->assertTrue($builder->build()->isProfane('sucker96'));
|
||||
}
|
||||
|
||||
public function test_match_exact_word_in_strict_mode()
|
||||
{
|
||||
$builder = new ProfaneValidatorBuilder();
|
||||
|
||||
// class is a safe word
|
||||
$this->assertFalse($builder->build()->isProfane('class', true));
|
||||
|
||||
// in strict mode this will pass a safe word
|
||||
$this->assertFalse($builder->build()->isProfane('sucker96', true));
|
||||
}
|
||||
|
||||
public function test_can_validate_a_bad_word_with_accent()
|
||||
{
|
||||
$builder = new ProfaneValidatorBuilder('sk');
|
||||
|
|
|
|||
|
|
@ -21,6 +21,25 @@ class StrTest extends TestCase
|
|||
$this->assertTrue(Str::containsCaseless('Fuck! This class is so bad!', 'fUcK'));
|
||||
}
|
||||
|
||||
public function test_text_does_not_contain_match_in_strict_mode()
|
||||
{
|
||||
$this->assertFalse(Str::containsCaseless('This class is so bad!', 'ass', true));
|
||||
$this->assertFalse(Str::containsCaseless('Theorem Analisys', 'anal', true));
|
||||
}
|
||||
|
||||
public function test_text_contains_match_in_strict_mode()
|
||||
{
|
||||
$this->assertTrue(Str::containsCaseless('This class is a crap!', 'crap', true));
|
||||
$this->assertFalse(Str::containsCaseless('Theorem Analisys', 'anal', true));
|
||||
$this->assertFalse(Str::containsCaseless('Sucker69', 'sucker', true));
|
||||
}
|
||||
|
||||
public function test_text_contains_match_in_not_strict_mode()
|
||||
{
|
||||
$this->assertTrue(Str::containsCaseless('This class is so bad!', 'ass', false));
|
||||
$this->assertTrue(Str::containsCaseless('Theorem Analisys', 'anal', false));
|
||||
}
|
||||
|
||||
public function test_text_contains_the_same_insensitive_match_from_string()
|
||||
{
|
||||
$this->assertTrue(Str::containsCaseless('Fuck! This class is so bad!', 'Fuck'));
|
||||
|
|
|
|||
|
|
@ -31,10 +31,14 @@ class ProfaneValidatorBuilder
|
|||
*
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function validate(array $parameters)
|
||||
public function validate(array $parameters, $strict = false)
|
||||
{
|
||||
list($attribute, $text, $dictionaries) = $parameters;
|
||||
|
||||
if ($strict) {
|
||||
return $this->build()->validateStrict($attribute, $text, $dictionaries);
|
||||
}
|
||||
|
||||
return $this->build()->validate($attribute, $text, $dictionaries);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue