Expected behavior
When using a pattern with trailing word boundary like pattern|fuck|``, the text "fuck!" should match because ! is a non-word character in the original input, and a common ending to sentences.
Actual behavior
"fuck!" does not match. The leet speak transformer converts ! to i, resulting in "fucki", which causes the trailing \b to fail since there's no word boundary between k and i.
Minimal reproducible example
import { RegExpMatcher, pattern, englishRecommendedTransformers } from 'obscenity';
const matcher = new RegExpMatcher({
blacklistedTerms: [{ id: 1, pattern: pattern`|fuck|` }],
...englishRecommendedTransformers,
});
console.log(matcher.hasMatch('fuck')); // true
console.log(matcher.hasMatch('fuck!')); // false (should be true)
Steps to reproduce
- Create a matcher with a pattern that has word boundaries at both ends (|word|)
- Use englishRecommendedTransformers (which includes resolveLeetSpeakTransformer)
- Test with a word followed by !
- Observe that the match fails
Additional context
This appears to be a regression (this didn't happen in 0.4.0). The leet speak dictionary now includes ! as a variant of i (useful for catching "pen!s"), but this breaks word boundary detection for common sentence-ending punctuation.
The issue is that word boundaries are evaluated on the transformed text rather than the original text positions.
Node.js version
v20.x (issue is not Node-version-specific)
Obscenity version
v0.4.5
Priority
Terms
Expected behavior
When using a pattern with trailing word boundary like pattern|fuck|``, the text "fuck!" should match because ! is a non-word character in the original input, and a common ending to sentences.
Actual behavior
"fuck!" does not match. The leet speak transformer converts ! to i, resulting in "fucki", which causes the trailing \b to fail since there's no word boundary between k and i.
Minimal reproducible example
Steps to reproduce
Additional context
This appears to be a regression (this didn't happen in 0.4.0). The leet speak dictionary now includes ! as a variant of i (useful for catching "pen!s"), but this breaks word boundary detection for common sentence-ending punctuation.
The issue is that word boundaries are evaluated on the transformed text rather than the original text positions.
Node.js version
v20.x (issue is not Node-version-specific)
Obscenity version
v0.4.5
Priority
Terms