fix: detect partial spacing profanity obfuscation - #44
Conversation
Profanity obfuscation using partial spacing was not being detected: - "s hit" not detected as "shit" - "f uck" not detected as "fuck" - "t wat" not detected as "twat" The isSpanningWordBoundary() method had overly strict logic that rejected legitimate partial spacing patterns. This fix modifies the method to check surrounding context instead of relying on heuristics about single-character parts: - If alphanumeric char immediately before match → embedded in word → reject - If alphanumeric char immediately after match → embedded in word → reject - Otherwise → standalone text, likely intentional obfuscation → allow Added 6 new test cases for partial spacing detection. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Changes
Sequence Diagram(s)(omitted — changes do not introduce multi-component sequential flows requiring a diagram) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/BlaspService.php`:
- Around line 435-452: preg_match_all returns byte offsets but the code treats
$matchStart as a character index when calling mb_substr/mb_strlen, which breaks
for multibyte strings; convert the byte offset to a character offset first (e.g.
compute $matchCharStart = mb_strlen(substr($fullString, 0, $matchStart),
'UTF-8')) and then compute $matchCharEnd = $matchCharStart +
mb_strlen($matchedText, 'UTF-8'), and use $matchCharStart/$matchCharEnd instead
of $matchStart/$matchEnd when deriving $charBefore and $charAfter and when
comparing against mb_strlen($fullString, 'UTF-8').
preg_match_all returns byte offsets, but mb_substr/mb_strlen expect character offsets. This fix converts the byte offset to a character offset before performing boundary checks, ensuring correct behavior with multibyte characters (accented letters, etc.). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
"s hit","f uck","t wat")isSpanningWordBoundary()to check surrounding context instead of relying on heuristicsProblem
Profanity obfuscation using partial spacing was not being detected:
"s hit"- not detected as "shit""f uck"- not detected as "fuck""t wat"- not detected as "twat""fu c k"- not detected as "fuck""tw a t"- not detected as "twat"The
isSpanningWordBoundary()method had overly strict logic that rejected legitimate partial spacing patterns when the first or last part was a single character.Solution
Modified
isSpanningWordBoundary()to check surrounding context:Test plan
"This musicals hit"not flagged)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.