Fix `18+` false positives with NSFW check

Was noticing this with our test room names like: `planet-1688081266353-room-18`
This commit is contained in:
Eric Eastwood 2023-06-29 18:49:25 -05:00
parent 5de8cb4e35
commit b7185c8231
2 changed files with 12 additions and 1 deletions

View File

@ -1,7 +1,13 @@
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const NSFW_WORDS = ['nsfw', 'porn', 'nudes', 'sex', '18+'];
const NSFW_REGEXES = NSFW_WORDS.map((word) => new RegExp(`(\\b|_)${word}(\\b|_)`, 'i'));
const NSFW_REGEXES = NSFW_WORDS.map(
// We use `(\b|_|-|\s|^)` instead of just `(\b|_)` because the word boundary doesn't
// match next to the `+` sign in `18+`
(word) => new RegExp(`(\\b|_|-|\\s|^)${escapeStringRegexp(word)}(\\b|_|-|\\s|$)`, 'i')
);
// A very basic check for NSFW content that just looks for some keywords in the given
// text

View File

@ -13,6 +13,11 @@ describe('checkTextForNsfw', () => {
NSFW_foo: true,
'NSFW-foo': true,
'NSFW:foo': true,
'18+ only': true,
// Previous false positives that we ran into in the wild that should not be flagged
// as NSFW
'1888-great-blizzard': false,
'argon-18-element': false,
}).forEach(([inputText, expectedNsfw]) => {
it(`should return ${expectedNsfw} for '${inputText}'`, () => {
assert.strictEqual(