Fixes #1. Match in caseless way
This commit is contained in:
parent
e9156ed51b
commit
076cde1a1b
|
|
@ -43,7 +43,7 @@ class ProfaneValidator
|
|||
*/
|
||||
public function isProfane($text)
|
||||
{
|
||||
return str_contains($text, $this->badwords);
|
||||
return Str::containsCaseless($text, $this->badwords);
|
||||
}
|
||||
|
||||
public function getBadwords()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace LaravelProfane;
|
||||
|
||||
class Str
|
||||
{
|
||||
/**
|
||||
* Taken from Illuminate\Support\Str
|
||||
* Determine if a given string contains a given word with case insensitive match.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
public static function containsCaseless($haystack, $needles)
|
||||
{
|
||||
foreach ((array) $needles as $needle) {
|
||||
$needle = preg_quote($needle);
|
||||
if ($needle != '' && preg_match("/$needle/iu", $haystack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -66,6 +66,16 @@ class ProfaneValidatorTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($profane->isProfane($word));
|
||||
}
|
||||
|
||||
public function test_can_evaluate_as_caseless_mode()
|
||||
{
|
||||
$word = '<b>FUCK</b> you BITCH if you read this.';
|
||||
$this->mockConfigs();
|
||||
|
||||
$profane = new ProfaneValidator();
|
||||
|
||||
$this->assertTrue($profane->isProfane($word));
|
||||
}
|
||||
|
||||
public function test_can_set_dictionary_when_you_pass_a_locale()
|
||||
{
|
||||
$this->mockConfigs();
|
||||
|
|
|
|||
Loading…
Reference in New Issue