mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
* update packages on local/origin repo * feat(challenges): add banned words & slur blocker to challenges * feat(challenges): slur blocker work * feat(challenges): slur blocker * feat(challenges): more slur blocker * feat(challenges): even more slur blocker * feat(challenges): swear and slur blocker * feat(challenges): update behavior based on public/private groups * feat(profiles): slur/swear blocker * feat(profiles): slur/swear blocker * feat(profiles/PMs): slur/swear blocker upgrade * feat(slur/swear): working on it * feat(profiles/challenges): work on profile block & slack report * feat(slur/swear blocker): work on Profiles * feat(slur blocker): refactoring code * feat(slur blocker): more refactoring * feat(slur blocker): arghhhhhh * fix(profiles): improve profanity check logic * fix(slack): update Slack notification to include authorEmail and remove undefined * feat(s/s blocker): work on challenges * feat(s/s blocker): challenge update * feat(s/s blocker): slack notifs refinements * feat(s/s blocker): refine slack notifs & disallow use of challenges POST API route if user is chatRevoked:true in db * update package.json and package-lock.json * attempt to disable create challenge button for muted users * another attempt to disable create challenge * block muted users from creating challenges * CSS button fun * fix CSS button * refactor(css): move button style to global Also, disable Clone button if user is chat revoked * fix(lint): remove unused fn * fix(challenges): handle null slur check * fix(groups): throw notFound earlier * fix(challenges): CSS and logic updates * fix(lint): remove whitespace * fix(challenges): don't disable create buttons * fix(slack): restore broken profile flag fields * chore(cleanup): remove comments and whitespace * chore(cleanup): one more white space --------- Co-authored-by: SabreCat <sabe@habitica.com>
62 lines
2.3 KiB
JavaScript
62 lines
2.3 KiB
JavaScript
import bannedSlurs from '../bannedSlurs';
|
|
import bannedWords from '../bannedWords';
|
|
import {
|
|
getMatchesByWordArray,
|
|
normalizeUnicodeString,
|
|
removePunctuationFromString,
|
|
} from '../stringUtils';
|
|
import forbiddenUsernames from '../forbiddenUsernames';
|
|
|
|
const bannedSlurRegexes = bannedSlurs.map(word => new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
|
const bannedWordRegexes = bannedWords.map(word => new RegExp(`\\b([^a-z]+)?${word}([^a-z]+)?\\b`, 'i'));
|
|
|
|
export function stringContainsProfanity (str, profanityType = 'bannedWord') {
|
|
const bannedRegexes = profanityType === 'slur' ? bannedSlurRegexes : bannedWordRegexes;
|
|
|
|
for (let i = 0; i < bannedRegexes.length; i += 1) {
|
|
const regEx = bannedRegexes[i];
|
|
const match = removePunctuationFromString(normalizeUnicodeString(str)).match(regEx);
|
|
if (match !== null && match[0] !== null) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function nameContainsNewline (username) {
|
|
return username.includes('\n');
|
|
}
|
|
|
|
function usernameIsForbidden (username) {
|
|
const forbiddenWordsMatched = getMatchesByWordArray(username, forbiddenUsernames);
|
|
return forbiddenWordsMatched.length > 0;
|
|
}
|
|
|
|
const invalidCharsRegex = new RegExp('[^a-z0-9_-]', 'i');
|
|
function usernameContainsInvalidCharacters (username) {
|
|
const match = username.match(invalidCharsRegex);
|
|
return match !== null && match[0] !== null;
|
|
}
|
|
|
|
export function verifyDisplayName (displayName, res) {
|
|
const issues = [];
|
|
if (displayName.length < 1 || displayName.length > 30) issues.push(res.t('displaynameIssueLength'));
|
|
if (stringContainsProfanity(displayName, 'slur')) issues.push(res.t('bannedSlurUsedInProfile'));
|
|
if (nameContainsNewline(displayName)) issues.push(res.t('displaynameIssueNewline'));
|
|
|
|
return issues;
|
|
}
|
|
|
|
export function verifyUsername (username, res, newUser = true) {
|
|
const slurMessage = newUser
|
|
? res.t('usernameIssueSlur')
|
|
: res.t('bannedSlurUsedInProfile');
|
|
const issues = [];
|
|
if (username.length < 1 || username.length > 20) issues.push(res.t('usernameIssueLength'));
|
|
if (usernameContainsInvalidCharacters(username)) issues.push(res.t('usernameIssueInvalidCharacters'));
|
|
if (stringContainsProfanity(username, 'slur') || stringContainsProfanity(username)) issues.push(slurMessage);
|
|
if (usernameIsForbidden(username)) issues.push(res.t('usernameIssueForbidden'));
|
|
|
|
return issues;
|
|
}
|