Skip to content

Commit 2ec13f5

Browse files
committed
Fix spam detector handling of unreadable special characters
1 parent 767bb5c commit 2ec13f5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Diff for: app/Services/SpamDetector.php

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public function hasTooManySpecialCharacters()
105105
->squish()
106106
->wordCount();
107107

108+
if($countWords === 0) {
109+
return true;
110+
}
111+
108112
$diff = ($withSpecialCharacters - $withOutSpecialCharacters) / 2;
109113

110114
// Proportion of special characters in the message

Diff for: tests/Unit/SpamDetectorTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,10 @@ public function testMessageOneSpecialCharacters(): void
144144
$spamDetector = new SpamDetector('🔥');
145145
$this->assertTrue($spamDetector->hasTooManySpecialCharacters());
146146
}
147+
148+
public function testMessageSpecialCharacters(): void
149+
{
150+
$spamDetector = new SpamDetector('✅ 🔤🔤🔤🔤 🔤🔤🔤🔤🔤🔤 ✅ 🔠🔠🔠🔠🔠 🔠 🔠🔠🔠🔠🔠🔠🔠 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥 🔥🔥🔥🔥🔥 ♦️🔺🔺♦️♦️ ♦️🔺🔺🔺 4️⃣2️⃣5️⃣💲 🔡 🔡🔡🔡🔡 ⚪️⚪️🔴⚪️⚪️🔴 🔴⚪️⚪️ 🔤🔤🔤🔤🔤🔤 🔤 🔤🔤');
151+
$this->assertTrue($spamDetector->hasTooManySpecialCharacters());
152+
}
147153
}

0 commit comments

Comments
 (0)