Skip to content

fix: detect partial spacing profanity obfuscation - #44

Merged
deemonic merged 2 commits into
mainfrom
fix/partial-spacing-detection
Jan 28, 2026
Merged

deemonic merged 2 commits into
mainfrom
fix/partial-spacing-detection

Conversation

@deemonic

@deemonic deemonic commented Jan 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes partial spacing profanity obfuscation not being detected (e.g., "s hit", "f uck", "t wat")
  • Updates isSpanningWordBoundary() to check surrounding context instead of relying on heuristics
  • Adds 6 new test cases for partial spacing detection

Problem

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:

  • If there's an alphanumeric character immediately before the match → it's embedded in a word → reject
  • If there's an alphanumeric character immediately after the match → it's embedded in a word → reject
  • Otherwise → standalone text, likely intentional obfuscation → allow

Test plan

  • All 194 existing tests pass
  • New test cases for partial spacing detection pass
  • False positive prevention still works ("This musicals hit" not flagged)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved profanity detection with Unicode-aware, context-sensitive word-boundary checks to better catch profanities split by spaces/characters and reduce false positives.
  • Tests

    • Added tests covering multiple spaced-profane patterns and a negative case to ensure legitimate phrases are not flagged.

✏️ Tip: You can customize this high-level summary in your review settings.

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>
@coderabbitai

coderabbitai Bot commented Jan 28, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The isSpanningWordBoundary method in BlaspService now accepts fullString and matchStart and uses Unicode-aware, context-sensitive logic to analyze surrounding characters and split parts; test coverage added for multiple partial-spacing profanity cases.

Changes

Cohort / File(s) Summary
Profanity boundary detection logic
src/BlaspService.php
Signature changed to isSpanningWordBoundary(string $matchedText, string $fullString, int $matchStart): bool. Implementation rewritten: early return for non-spacing matches, Unicode-aware splitting and counting (mb_strlen, mb_substr), context checks of chars before/after match, and nuanced embedding rules to decide when a match spans word boundaries.
Partial-spacing test coverage
tests/BlaspCheckTest.php
Added multiple tests for spaced/partially-spaced profanity (s hit, f uck, t wat, fu c k, tw a t) and a negative case ensuring no false positive for an embedded phrase.

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

🐰
I hop through strings both wide and thin,
I sniff the gaps where sly words grin,
With Unicode ears and careful eye,
No crafty swear can slip on by.
A tidy patch — a tidy nibble!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: detect partial spacing profanity obfuscation' directly and specifically describes the main change: improving detection of profanity that has been obfuscated through partial spacing (e.g., 's hit' for 'shit').
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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').

Comment thread src/BlaspService.php
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>
@deemonic
deemonic merged commit 7190213 into main Jan 28, 2026
3 checks passed
@deemonic
deemonic deleted the fix/partial-spacing-detection branch January 28, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant