Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Words without spaces aren't filtered #140

Open
lafkpages opened this issue Jan 31, 2022 · 4 comments
Open

Words without spaces aren't filtered #140

lafkpages opened this issue Jan 31, 2022 · 4 comments

Comments

@lafkpages
Copy link

If I put many words together without spaces it doesn't filter them.

@jayli3n
Copy link

jayli3n commented Feb 25, 2022

Kind of defeats the purpose of this package...

@ishmaelmoreno
Copy link

This is a bummer! now noticed this happens... sigh

@KModestas
Copy link

yup

@lafkpages
Copy link
Author

I made a simple function that fixes it:

function cleanBadWords(s, filter = badWordsFilter) {
  s = s.replace(/\u200B|\u200C|\x00/g, '');

  for (const swear of filter.list) {
    if (filter.exclude && filter.exclude.includes(swear.toLowerCase())) {
      continue;
    }

    s = s.replace(
      new RegExp(
        swear.replace(/([\.\*\-\\\/\?\+\{\}\[\]\|\(\)])/g, '\\$1'),
        'gi'
      ),
      '*'.repeat(swear.length)
    );
  }

  return s;
}
``

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

No branches or pull requests

4 participants