This commit is contained in:
Riley Davis
2017-01-06 13:23:51 -07:00
parent a3bb8e2f41
commit abd2332745
+5 -6
View File
@@ -3,7 +3,7 @@ const _ = require('lodash');
const natural = require('natural');
const tokenizer = new natural.WordTokenizer();
const Setting = require('../models/setting');
const errors = require('../errors');
const Errors = require('../errors');
/**
* The root wordlist object.
@@ -144,7 +144,7 @@ class Wordlist {
if (this.match(this.lists.banned, phrase)) {
debug(`the field "${field}" contained a phrase "${phrase}" which contained a banned word/phrase`);
errors.banned = errors.ErrContainsProfanity;
errors.banned = Errors.ErrContainsProfanity;
// Stop looping through the fields now, we discovered the worst possible
// situation (a banned word).
@@ -155,7 +155,7 @@ class Wordlist {
if (this.match(this.lists.suspect, phrase)) {
debug(`the field "${field}" contained a phrase "${phrase}" which contained a suspected word/phrase`);
errors.suspect = errors.ErrContainsProfanity;
errors.suspect = Errors.ErrContainsProfanity;
// Continue looping through the fields now, we discovered a possible bad
// word (suspect).
@@ -174,13 +174,14 @@ class Wordlist {
return wl.load()
.then(() => {
displayName = displayName.replace(/_/g, '');
// test each word, and fail if we find a match
const hasBadWords = wl.lists.banned.some(word => {
return new RegExp(word, 'ig').test(displayName);
});
if (hasBadWords) {
throw errors.ErrContainsProfanity;
throw Errors.ErrContainsProfanity;
} else {
return Promise.resolve(displayName);
}
@@ -216,6 +217,4 @@ class Wordlist {
}
}
module.exports = Wordlist;