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

Bypassed by plural profanities #12

Open
3dfoster opened this issue May 12, 2017 · 4 comments
Open

Bypassed by plural profanities #12

3dfoster opened this issue May 12, 2017 · 4 comments

Comments

@3dfoster
Copy link

Simply adding an 's' to the end of a profanity defeats the filter.
For example, "No fucks given" is not censored.

@no-stack-dub-sack
Copy link

no-stack-dub-sack commented May 16, 2017

@raymondjavaxx This is a totally awesome package and exactly what I was looking for! However, I did notice this issue and that you can also get "compound" curses, so to speak, to pass. For example, "sh-tfu-k" is not on your default list, and while adding each additional word is of course possible with the way you have it set up, I wonder if you would be open to me submitting a PR that solves both of these issues without the need for adding additional specific words? I have a working solution locally and I would love to show it to you / discuss it.

A couple of examples:

swearjar.profane('no f-cks given') // true
swearjar.censor('no f-cks given') // no ***** given
swearjar.censor('sh-ttyf-cks') // ***********

Let me know! Thanks.

@loctn
Copy link

loctn commented May 24, 2017

@no-stack-dub-sack the compound stuff is tricky without significantly altering (and slowing down) the scanning algorithm.

@fasterthan plurals should be an easy fix, I'll see if I can get to it.

@loctn
Copy link

loctn commented May 24, 2017

@fasterthan actually this could be covered by #11 so I'll hold off for now.

@no-stack-dub-sack
Copy link

@loctn Yeah, upon a closer look, and deeper testing with the solution I had, I did run into some tricky situations. Namely censoring common words that contained swears. For instance, class was censored because it contained an obvious curse. However, for my use case, this was fine, I just took "ass" off the list because it's less offensive than many others, and keeping the compound coverage seemed more important at the time.

This was the edit I made to the scan method:

  scan: function (text, callback) {
    var word, key, match;
    var regex = /\w+/g

    while (match = regex.exec(text)) {
      word = match[0];
      key  = word.toLowerCase();

      if (key in this._badWords && Array.isArray(this._badWords[key])) {
        if (callback(word, match.index, this._badWords[key]) === false) {
          break;
        }
      } else {
        /******* added else statement to catch compound bad words and plurals such as
        "no fu*ks given" and "fu*ksh*t" without having to add each to default list */
        for (let badWord in this._badWords) {
          if (key.search(badWord) > -1) {
            if (callback(key, match.index, this._badWords[badWord]) === false) {
              break;
            }
          }
        }
      }
    }
  },

Again, may not be ideal, but working well for my use-case.

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

3 participants