web-mech / badwords

A javascript filter for badwords
MIT License
618 stars 325 forks source link

Issue with symbols / emoji only strings #93

Open lkgoerges opened 3 years ago

lkgoerges commented 3 years ago

When running the clean() function with a string containing only emojis or symbols I receive the following error:

TypeError: Cannot read property '0' of null
at Filter.clean in bad-words/lib/badwords.js — line 58

As a workaround, I currently add "ABC" at the end of every string and remove it after the cleanup.

Example code:

const ProfanityFilter = require('bad-words');
const profanityFilter = new ProfanityFilter();
profanityFilter.clean('🙂');
profanityFilter.clean('.,-*');

Screenshot_127

Fitmavincent commented 3 years ago

Getting the same problem. Will try the workaround by @lkgoerges

cbmmd42 commented 3 years ago

For those interested, I'm using this as a workaround for now.

// filename bad-words-hacked.js
const Filter = require('bad-words')

class FilterHacked extends Filter {
    cleanHacked(string) {
        try {
            return this.clean(string);
        } catch {
            const joinMatch = this.splitRegex.exec(string);
            const joinString = (joinMatch && joinMatch[0]) || '';
            return string.split(this.splitRegex).map((word) => {
              return this.isProfane(word) ? this.replaceWord(word) : word;
            }).join(joinString);
        }
      }
}

module.exports = FilterHacked

Example code:

var Filter = require('./bad-words-hacked');
filter = new Filter();
const filteredString = filter.cleanHacked(string);
iandoesallthethings commented 8 months ago

Looks like this repo is pretty much abandoned. Does anyone have a fork they plan on maintaining?