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

Don't crash w/strings with no word boundaries #95

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

brianreavis
Copy link

Fixes #93

TypeError: Cannot read property '0' of null

"TypeError: Cannot read property '0' of null"
@aksperiod
Copy link

can this get merged? it seems like a huge oversight to crash with a wordless string.

@fenix20113
Copy link

Any news on this PR when it can be merged?

@heartz66
Copy link

Any updates?

@StanFlint
Copy link

I would just like to place another vote to merge this PR. I would love to use this package in production but can't due to this error.

@IsaiahPapa
Copy link

IsaiahPapa commented Jan 5, 2022

I would just like to place another vote to merge this PR. I would love to use this package in production but can't due to this error.

I yoinked some code from the changes in this pr, but I just overrode the clean method to fit my needs. Kinda a pain in the behind if you have multiple filters but guess this is all we can do unless we want to fork and make our own... or wait.

let customFilter = new Filter({
    placeHolder: "*",
});
customFilter.clean = (string) => {
    try {
        const splitMap = string.split(ProfaneFilter.splitRegex).map((word) => {
            return ProfaneFilter.isProfane(word) ? ProfaneFilter.replaceWord(word) : word;
        });
        if (splitMap.length < 2) return string;
        return splitMap.join(ProfaneFilter.splitRegex.exec(string)[0]);
    } catch (e) {
        return string;
    }
};
customFilter.clean("you are a meanie");

@iplanwebsites
Copy link

Would love this PR to be merged to prevent crashing on strings like :)

@spravo
Copy link

spravo commented Jun 7, 2022

or like this ...

import BaseBadWordsFilter from 'bad-words';

class BadWordsFilter extends BaseBadWordsFilter {
  private readonly splitRegex!: RegExp;

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

@web-mech web-mech added the help wanted we need help with this problem label Jan 5, 2023
@web-mech web-mech changed the base branch from master to next January 5, 2023 14:48
@UberMC
Copy link

UberMC commented Feb 20, 2023

This really needs to be addressed the Library is poor without it

@skyelynwaddell
Copy link

thanks for the fix

@ribaptista
Copy link

@spravo @IsaiahPapa why is the try block necessary?

@iplanwebsites
Copy link

This wrapper will fix most issues listed on the issue tabs. We'll get there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted we need help with this problem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with symbols / emoji only strings