From 8570f74a2446403e9ee9875ab1b0f4df87c3ae88 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 30 Jan 2026 14:23:18 +0100 Subject: [PATCH] Trim trailing whitespaces in profile data --- backend/api/src/create-profile.ts | 19 +++++++++++-------- backend/api/src/update-profile.ts | 18 ++++++++++-------- common/src/parsing.ts | 10 ++++++++++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/backend/api/src/create-profile.ts b/backend/api/src/create-profile.ts index 9fc7bf19..b9efb837 100644 --- a/backend/api/src/create-profile.ts +++ b/backend/api/src/create-profile.ts @@ -1,14 +1,15 @@ -import { APIError, APIHandler } from 'api/helpers/endpoint' -import { createSupabaseDirectClient } from 'shared/supabase/init' -import { log, getUser } from 'shared/utils' +import {APIError, APIHandler} from 'api/helpers/endpoint' +import {createSupabaseDirectClient} from 'shared/supabase/init' +import {getUser, log} from 'shared/utils' import {HOUR_MS, MINUTE_MS, sleep} from 'common/util/time' -import { removePinnedUrlFromPhotoUrls } from 'shared/profiles/parse-photos' -import { track } from 'shared/analytics' -import { updateUser } from 'shared/supabase/users' -import { tryCatch } from 'common/util/try-catch' -import { insert } from 'shared/supabase/utils' +import {removePinnedUrlFromPhotoUrls} from 'shared/profiles/parse-photos' +import {track} from 'shared/analytics' +import {updateUser} from 'shared/supabase/users' +import {tryCatch} from 'common/util/try-catch' +import {insert} from 'shared/supabase/utils' import {sendDiscordMessage} from "common/discord/core"; import {jsonToMarkdown} from "common/md"; +import {trimStrings} from "common/parsing"; export const createProfile: APIHandler<'create-profile'> = async (body, auth) => { const pg = createSupabaseDirectClient() @@ -23,6 +24,8 @@ export const createProfile: APIHandler<'create-profile'> = async (body, auth) => } await removePinnedUrlFromPhotoUrls(body) + trimStrings(body) + const user = await getUser(auth.uid) if (!user) throw new APIError(401, 'Your account was not found') if (user.createdTime > Date.now() - HOUR_MS) { diff --git a/backend/api/src/update-profile.ts b/backend/api/src/update-profile.ts index 0e2d5d47..e58e2d0c 100644 --- a/backend/api/src/update-profile.ts +++ b/backend/api/src/update-profile.ts @@ -1,16 +1,18 @@ -import { APIError, APIHandler } from 'api/helpers/endpoint' -import { removePinnedUrlFromPhotoUrls } from 'shared/profiles/parse-photos' -import { createSupabaseDirectClient } from 'shared/supabase/init' -import { updateUser } from 'shared/supabase/users' -import { log } from 'shared/utils' -import { tryCatch } from 'common/util/try-catch' -import { update } from 'shared/supabase/utils' -import { type Row } from 'common/supabase/utils' +import {APIError, APIHandler} from 'api/helpers/endpoint' +import {removePinnedUrlFromPhotoUrls} from 'shared/profiles/parse-photos' +import {createSupabaseDirectClient} from 'shared/supabase/init' +import {updateUser} from 'shared/supabase/users' +import {log} from 'shared/utils' +import {tryCatch} from 'common/util/try-catch' +import {update} from 'shared/supabase/utils' +import {type Row} from 'common/supabase/utils' +import {trimStrings} from "common/parsing"; export const updateProfile: APIHandler<'update-profile'> = async ( parsedBody, auth ) => { + trimStrings(parsedBody) log('Updating profile', parsedBody) const pg = createSupabaseDirectClient() diff --git a/common/src/parsing.ts b/common/src/parsing.ts index 1d83ac82..7170e8fc 100644 --- a/common/src/parsing.ts +++ b/common/src/parsing.ts @@ -1,3 +1,13 @@ export const toKey = (str: string | number | boolean) => { return String(str).replace(/ /g, '_').toLowerCase() +} + +export function trimStrings>(body: T): T { + for (const key in body) { + const value = (body[key] as unknown | string) + if (typeof value === 'string') { + body[key] = value.trim() as T[typeof key] + } + } + return body } \ No newline at end of file