From b0ff26ffe0450362f9fcdcf2bcc1c53487f213c0 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 1 Aug 2024 19:56:44 -0400 Subject: [PATCH] refactor: Include sanity check for name color --- src/pages/api/account/tag.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/pages/api/account/tag.js b/src/pages/api/account/tag.js index 9a5b851..b416278 100644 --- a/src/pages/api/account/tag.js +++ b/src/pages/api/account/tag.js @@ -4,7 +4,6 @@ import { isBlank, isBoolean } from '@/lib/utils/utils' import { isValidCoverRegion } from '@/lib/constants/forms/coverRegions' import { isValidCoverType } from '@/lib/constants/forms/coverTypes' import { isValidOverlay } from '@/lib/constants/forms/overlays' -import { BACKGROUNDS } from '@/lib/constants/forms/backgrounds' import { isValidFlag } from '@/lib/constants/forms/flags' import { isValidCoin } from '@/lib/constants/forms/coins' import { isValidFont } from '@/lib/constants/forms/fonts' @@ -29,26 +28,26 @@ async function updateTagSettings (request, response) { } = request.body const username = request.session?.username - function validateFriendCode () { - if (!request.body.comment) { - return true - } - - return true - } - - if (!validateFriendCode()) { - return response - .status(HTTP_CODE.BAD_REQUEST) - .send({ error: 'Invalid data' }) - } - if (!username) { return response .status(HTTP_CODE.UNAUTHORIZED) .json({ error: 'Unauthorized' }) } + if (nameColor) { + if (nameColor.length !== 7) { + return response + .status(HTTP_CODE.BAD_REQUEST) + .send({ error: 'Invalid data' }) + } + + if (!(/(#[a-fA-F0-9]{6})/.test(nameColor))) { + return response + .status(HTTP_CODE.BAD_REQUEST) + .send({ error: 'Invalid data' }) + } + } + if ( isBlank(nameOnRiiTag) || isBlank(coverRegion) ||