Improve profanity expectation to not match when it has profanity as s…#63
Merged
JonPurvis merged 1 commit intopestphp:masterfrom Jun 1, 2025
Conversation
Collaborator
|
Thanks for this! V4 actually removes the tolerated file completely. If you want to take V4 for a test, go right ahead! I'll get this merged and tag a new release for V3 though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I found some edge cases in Portuguese where words that are perfectly safe contain profanities as substrings, causing our check to throw exceptions incorrectly. The same happens in English.
Examples
In Portuguese:
In English:
Previously, we’ve been solving these issues by adding false positives to src/Config/tolerated.php. However, that requires manual effort and doesn't scale well — we would constantly need to add new combinations.
Instead, a better approach would be to detect whether a profanity appears as an exact isolated word, not as a substring inside a larger, valid word.
How do we detect this?
We will improve the detection logic to identify profanities only when they appear as isolated words, based on:
Code Explanation
src/Expectations/Profanity.php — Line 50
Matches:
Line 54 — snake_case detection:
Matches:
Line 65 — camelCase/PascalCase detection:
Matches:
Benefits of This Change
This approach improves scalability and accuracy. For example: