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

bug: grawlixCensorStrategy sometimes generates "@$$" #82

Open
3 of 5 tasks
eltoder opened this issue Nov 26, 2024 · 1 comment · May be fixed by #85
Open
3 of 5 tasks

bug: grawlixCensorStrategy sometimes generates "@$$" #82

eltoder opened this issue Nov 26, 2024 · 1 comment · May be fixed by #85
Labels
bug Something isn't working

Comments

@eltoder
Copy link
Contributor

eltoder commented Nov 26, 2024

Expected behavior

Censoring strategy should generate a replacement string that itself does not contain any profanity. However, since grawlixCensorStrategy returns a string of random characters that include "@" and "$", sometimes it generates "@$$", which is considered profanity by the default englishDataset/englishRecommendedTransformers matcher recommended in the guide.

Actual behavior

This causes TextCensor with the default settings to sometimes replace "ass" or "@$$" with "@$$".

Minimal reproducible example

const {
	RegExpMatcher,
	TextCensor,
	englishDataset,
	englishRecommendedTransformers,
} = require('obscenity');

const matcher = new RegExpMatcher({
	...englishDataset.build(),
	...englishRecommendedTransformers,
});

const censor = new TextCensor();
const input = '@$$';
const matches = matcher.getAllMatches(input);
for (let i = 0; i < 100; i++) {
    if (censor.applyTo(input, matches) === input)
        console.log("input did not change after censoring");
}

Steps to reproduce

No response

Additional context

No response

Node.js version

v20

Obscenity version

v0.4.0

Priority

  • Low
  • Medium
  • High

Terms

  • I agree to follow the project's Code of Conduct.
  • I have searched existing issues for similar reports.
@eltoder eltoder added the bug Something isn't working label Nov 26, 2024
@jo3-l
Copy link
Owner

jo3-l commented Nov 27, 2024

Interesting find (and a mildly unfortunate issue)! A PR to generate another random string (in a loop as needed) if @$$ was output originally is welcome. I can't guarantee a release within the next month, so if you need an immediate fix you can switch to one of the other censor strategies provided, which do not suffer from this problem.

eltoder added a commit to eltoder/obscenity that referenced this issue Nov 28, 2024
eltoder added a commit to eltoder/obscenity that referenced this issue Nov 29, 2024
In randomCharFromSetCensorStrategy(). This produces more interesting
strings and avoids generating "@$$" as a side-effect.

Fixes jo3-l#82
@eltoder eltoder linked a pull request Nov 29, 2024 that will close this issue
8 tasks
eltoder added a commit to eltoder/obscenity that referenced this issue Dec 3, 2024
In randomCharFromSetCensorStrategy(). This produces more interesting
strings and avoids generating "@$$" as a side-effect.

Fixes jo3-l#82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants