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

Issue with symbols / emoji only strings #93

Open
lkgoerges opened this issue Nov 22, 2020 · 3 comments · May be fixed by #95
Open

Issue with symbols / emoji only strings #93

lkgoerges opened this issue Nov 22, 2020 · 3 comments · May be fixed by #95

Comments

@lkgoerges
Copy link

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
Copy link

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

Fitmavincent referenced this issue Nov 24, 2020
Issue:
Using /\b/ to split the text is limited to languages using only the 63
characters:

```
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 _
```

cf https://stackoverflow.com/a/2449892

For example, in French, the string `je suis français` will be split into
`["je", " ", "suis", " ", "fran", "ç", "ais"]` which won't allow to
perform the bad-words cleaning.

Therefore I added an option `splitRegex` which allow to overwrite the
regex used to split.
brianreavis added a commit to naturalatlas/badwords that referenced this issue Dec 4, 2020
"TypeError: Cannot read property '0' of null"
brianreavis added a commit to naturalatlas/badwords that referenced this issue Dec 4, 2020
"TypeError: Cannot read property '0' of null"
@brianreavis brianreavis linked a pull request Dec 4, 2020 that will close this issue
johnnyapol added a commit to TornDotSpace/Torn that referenced this issue Dec 29, 2020
This isn't so much of a fix as it is a workaround.
web-mech/badwords#93 tracks the issue.

This change also includes a minor fix to kick clients for exceptions in debug mode.
@cbmmd42
Copy link

cbmmd42 commented Apr 16, 2021

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);

callumooi pushed a commit to OtherOceanInteractive/badwords that referenced this issue Apr 19, 2021
"TypeError: Cannot read property '0' of null"
@iandoesallthethings
Copy link

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

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

Successfully merging a pull request may close this issue.

4 participants