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

Event Name Validation: blacklisted strings #1805

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import validator from 'validator';
import { isWordInArrayInString } from './../../../utils/stringUtils.js';
import { eventNameBlacklistArr } from '../../../utils/blacklist.js';

const validateEventForm = (vals, projectToEdit) => {
let newErrors = {};
Object.keys(vals).forEach((key) => {
let blacklistedStrings = isWordInArrayInString( eventNameBlacklistArr, vals[key].toLowerCase() );
switch (key) {
case 'name':
// Required
if (!vals[key]) {
newErrors = { ...newErrors, name: 'Event name is required' };
} else if (
isWordInArrayInString(
['meeting', 'mtg'],
vals[key].toLowerCase()
)
) {
} else if (blacklistedStrings) {
newErrors = {
...newErrors,
name: "Event name cannot contain 'meeting' or 'mtg'",
name: `Event name cannot contain: ${blacklistedStrings.join(', ')}`,
};
} else if (
isWordInArrayInString(
Expand Down
19 changes: 19 additions & 0 deletions client/src/utils/blacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const eventNameBlacklistArr = [
'general',
'meet',
'meeting',
'mtg',
'onboarding',
'onboard',
'team',
'semi',
'bi',
'weekly',
'monthly',
'annual',
'annually',
'bi-weekly',
'twice-weekly',
'semi-annual',
'semi-annually',
]
6 changes: 5 additions & 1 deletion client/src/utils/stringUtils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
export const isWordInArrayInString = (arr, str) => {
const words = str.split(' ');
let foundWords = []
for (let word of words) {
if (arr.includes(word)) {
return true;
foundWords.push(word)
}
}
if(foundWords.length > 0) {
return foundWords
}
return false;
};
Loading