fix(regexp): escape inputs

This commit is contained in:
Matteo Pagliazzi
2020-04-28 16:00:17 +02:00
parent 783b8995b8
commit b947c714f0
3 changed files with 13 additions and 3 deletions

View File

@@ -1,8 +1,12 @@
import escapeRegExp from 'lodash/escapeRegExp';
import bannedSlurs from '../bannedSlurs';
import { getMatchesByWordArray } from '../stringUtils';
import forbiddenUsernames from '../forbiddenUsernames';
const bannedSlurRegexs = bannedSlurs.map(word => new RegExp(`.*${word}.*`, 'i'));
const bannedSlurRegexs = bannedSlurs.map(word => {
const escapedWord = escapeRegExp(word);
return new RegExp(`.*${escapedWord}.*`, 'i');
});
export function nameContainsSlur (username) {
for (let i = 0; i < bannedSlurRegexs.length; i += 1) {