From 6c9ee414446d08b54ca631f61106a9534615919e Mon Sep 17 00:00:00 2001 From: Oxey <44652133+O-X-E-Y@users.noreply.github.com> Date: Thu, 26 Jan 2023 14:09:11 +0100 Subject: [PATCH] Make quote actions not break with c++ language (#3925) o-x-e-y * Make quote actions not break with c++ c++ currently obviously has `+` symbols which means stuff like quote ratings break because of the validation regex. I feel like changing `\w` straight to `.` would also be fine since languages and their names get approved manually, but this should work fine for now * fix silly mistake a `.regex()` got removed for whatever reason * Fix prettier bug * remove unnecessary spaces Co-authored-by: Rizwan Mustafa --- backend/src/api/routes/quotes.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/src/api/routes/quotes.ts b/backend/src/api/routes/quotes.ts index ccab312cc..70204d232 100644 --- a/backend/src/api/routes/quotes.ts +++ b/backend/src/api/routes/quotes.ts @@ -41,7 +41,10 @@ router.post( body: { text: joi.string().min(60).required(), source: joi.string().required(), - language: joi.string().regex(/^\w+$/).required(), + language: joi + .string() + .regex(/^[\w+]+$/) + .required(), captcha: joi.string().required(), }, validationErrorMessage: "Please fill all the fields", @@ -85,7 +88,10 @@ router.get( validateRequest({ query: { quoteId: joi.string().regex(/^\d+$/).required(), - language: joi.string().regex(/^\w+$/).required(), + language: joi + .string() + .regex(/^[\w+]+$/) + .required(), }, }), asyncHandler(QuoteController.getRating) @@ -99,7 +105,10 @@ router.post( body: { quoteId: joi.number().required(), rating: joi.number().min(1).max(5).required(), - language: joi.string().regex(/^\w+$/).required(), + language: joi + .string() + .regex(/^[\w+]+$/) + .required(), }, }), asyncHandler(QuoteController.submitRating) @@ -122,7 +131,7 @@ router.post( validateRequest({ body: { quoteId: withCustomMessages.regex(/\d+/).required(), - quoteLanguage: withCustomMessages.regex(/^\w+$/).required(), + quoteLanguage: withCustomMessages.regex(/^[\w+]+$/).required(), reason: joi .string() .valid(