From 4013c26bb7f39ef2c5da7bf7e5b04e0e8d5b2e8d Mon Sep 17 00:00:00 2001 From: keyan Date: Fri, 8 Dec 2023 14:31:06 -0600 Subject: [PATCH] add minimum title length --- lib/constants.js | 1 + lib/validate.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 05cbb217..d9d46233 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -22,6 +22,7 @@ export const TERRITORY_BILLING_TYPES = ['MONTHLY', 'YEARLY', 'ONCE'] export const TERRITORY_GRACE_DAYS = 5 export const COMMENT_DEPTH_LIMIT = 8 export const MAX_TITLE_LENGTH = 80 +export const MIN_TITLE_LENGTH = 5 export const MAX_POST_TEXT_LENGTH = 100000 // 100k export const MAX_COMMENT_TEXT_LENGTH = 10000 // 10k export const MAX_TERRITORY_DESC_LENGTH = 140 diff --git a/lib/validate.js b/lib/validate.js index da2eb542..be8f71ba 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -2,7 +2,7 @@ import { string, ValidationError, number, object, array, addMethod, boolean } fr import { BOOST_MIN, MAX_POLL_CHOICE_LENGTH, MAX_TITLE_LENGTH, MAX_POLL_NUM_CHOICES, MIN_POLL_NUM_CHOICES, MAX_FORWARDS, BOOST_MULT, MAX_TERRITORY_DESC_LENGTH, POST_TYPES, - TERRITORY_BILLING_TYPES, MAX_COMMENT_TEXT_LENGTH, MAX_POST_TEXT_LENGTH + TERRITORY_BILLING_TYPES, MAX_COMMENT_TEXT_LENGTH, MAX_POST_TEXT_LENGTH, MIN_TITLE_LENGTH } from './constants' import { URL_REGEXP, WS_REGEXP } from './url' import { SUPPORTED_CURRENCIES } from './currency' @@ -46,7 +46,7 @@ addMethod(string, 'or', function (schemas, msg) { const titleValidator = string().required('required').trim().max( MAX_TITLE_LENGTH, ({ max, value }) => `-${Math.abs(max - value.length)} characters remaining` -) +).min(MIN_TITLE_LENGTH, `must be at least ${MIN_TITLE_LENGTH} characters`) const textValidator = (max) => string().trim().max( max,