Skip to content

Commit 1ec9f98

Browse files
committed
fix: logic
1 parent 994bbe8 commit 1ec9f98

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Aman.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ public function __construct()
7676
*/
7777
private function getFilterRegexp(string $string): string
7878
{
79-
$replace = str_ireplace(array_keys($this->similar), array_values($this->similar), $string);
80-
return '/' . $replace . '/iu';
79+
$replace = strval(preg_replace_callback('/[a-z]/i', function (array $matches): string {
80+
return strval($this->similar[strtolower($matches[0])] ?? $matches[0]);
81+
}, $string));
82+
83+
return '/\b' . $replace . '\b/iu';
8184
}
8285

8386
/**

tests/Test.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function testCheck(): void
1919
{
2020
$this->assertTrue($this->aman->check('This is a test with b@jIng4n word'));
2121

22+
$this->assertFalse($this->aman->check('This banjir word'));
23+
2224
$this->assertFalse($this->aman->check('This is a clean test'));
2325
}
2426

@@ -27,6 +29,9 @@ public function testMasking(): void
2729
$maskedString = $this->aman->masking('This is a test with b@jIng4n word');
2830
$this->assertSame('This is a test with ******** word', $maskedString);
2931

32+
$maskedFalse = $this->aman->masking('This banjir word');
33+
$this->assertSame('This banjir word', $maskedFalse);
34+
3035
$maskedStringWithHash = $this->aman->masking('This is a test with b@jIng4n word', '#');
3136
$this->assertSame('This is a test with ######## word', $maskedStringWithHash);
3237
}
@@ -35,6 +40,9 @@ public function testFilter(): void
3540
{
3641
$filteredString = $this->aman->filter('This is a test with b@jIng4n word');
3742
$this->assertSame('This is a test with word', $filteredString);
43+
44+
$filteredString = $this->aman->filter('This banjir word');
45+
$this->assertSame('This banjir word', $filteredString);
3846
}
3947

4048
public function testWords(): void
@@ -45,6 +53,9 @@ public function testWords(): void
4553
$filteredWords = $this->aman->words('This is a test with b@jIng4n and k3p4rat word');
4654
$this->assertSame(['b@jIng4n', 'k3p4rat'], $filteredWords);
4755

56+
$cleanWords = $this->aman->words('This banjir word');
57+
$this->assertSame([], $cleanWords);
58+
4859
$cleanWords = $this->aman->words('This is a clean test');
4960
$this->assertSame([], $cleanWords);
5061
}

0 commit comments

Comments
 (0)