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: Kung Fu false positive #67

Closed
3 of 5 tasks
krasnoperov opened this issue Jul 13, 2024 · 3 comments
Closed
3 of 5 tasks

bug: Kung Fu false positive #67

krasnoperov opened this issue Jul 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@krasnoperov
Copy link

Expected behavior

matcher.hasMatch('Kung-Fu') returns true

Actual behavior

matcher.hasMatch('Kung-Fu') returns false

Minimal reproducible example

import assert from 'node:assert'

import {
  englishDataset,
  englishRecommendedTransformers,
  RegExpMatcher,
} from 'obscenity'

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

assert.equal(matcher.hasMatch('Kung-Fu'), false)
assert.equal(matcher.hasMatch('Kung Fu'), false)
assert.equal(matcher.hasMatch('Kung Fu Panda'), false)

// This one actually works
assert.equal(matcher.hasMatch('KungFu'), false)

Steps to reproduce

  1. Run the code above
  2. It falls with assert exception

Additional context

No response

Node.js version

v20.15.0

Obscenity version

0.2.1

Priority

  • Low
  • Medium
  • High

Terms

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

jo3-l commented Jul 16, 2024

The default dataset contains the pattern |fu|, which (correctly, but undesirably) matches on the -Fu in Kung-Fu. There are two potential ways we could fix this issue:

  1. Remove the |fu| pattern entirely, or
  2. Whitelist Kung-Fu and leave the |fu| pattern untouched.

I am leaning toward 2) at the moment: the |fu| pattern seems useful in general, and I cannot think of any other egregious false positives other than the instance you report. What do you think?

@krasnoperov
Copy link
Author

I think that whitelisting Kung-Fu is a good option here. Also, it is possible to handle any future false positives by adding them to the whitelist as they arise.

@jo3-l jo3-l closed this as completed in d60b4f4 Jul 17, 2024
@jo3-l
Copy link
Owner

jo3-l commented Jul 17, 2024

I released v0.3.1 with the fix (please ignore v0.2.2 and v0.3.0, both of which were problematic due to my botching some release automation—sorry for the noise!). Thanks again for the report.

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
Development

No branches or pull requests

2 participants