jo3-l / obscenity

Robust, extensible profanity filter for NodeJS
MIT License
70 stars 2 forks source link

bug: Censoring of the n-word results in more asterisks than expected #48

Closed HatScripts closed 8 months ago

HatScripts commented 8 months ago

Expected behavior

-

Actual behavior

matcher.getAllMatches('nigger') results in an array of length 2, when it should only be 1. This causes the resulting censored string to be n*********r, when it should be n****r.

Screenshot 2024-01-05 171832

Minimal reproducible example

import {
  RegExpMatcher,
  TextCensor,
  englishDataset,
  englishRecommendedTransformers,
  keepStartCensorStrategy,
  keepEndCensorStrategy,
  asteriskCensorStrategy
} from 'obscenity'

const matcher = new RegExpMatcher({
  ...englishDataset.build(),
  ...englishRecommendedTransformers
})

const strategy = keepStartCensorStrategy(keepEndCensorStrategy(asteriskCensorStrategy()))
const censor = new TextCensor().setStrategy(strategy)

const input = 'nigger'

const matches = matcher.getAllMatches(input)
console.log(matches)
console.log(censor.applyTo(input, matches))

Steps to reproduce

  1. Run above code
  2. View console

Additional context

No response

Node.js version

N/A

Obscenity version

v0.1.4

Priority

Terms

jo3-l commented 8 months ago

This should be fixed in the newest release of Obscenity; please let me know if it persists for you.

HatScripts commented 8 months ago

It's working as expected now. Thank you!