Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
16 changes: 13 additions & 3 deletions apps/web/lib/actions/partners/update-partner-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { partnerProfileChangeHistoryLogSchema } from "@/lib/zod/schemas/partner-
import {
MAX_PARTNER_DESCRIPTION_LENGTH,
PartnerProfileDetailsSchema,
sanitizeFormulaInput,
} from "@/lib/zod/schemas/partners";
import {
APP_DOMAIN_WITH_NGROK,
Expand All @@ -29,13 +30,22 @@ import { authPartnerActionClient } from "../safe-action";

const updatePartnerProfileSchema = z
.object({
name: z.string().trim().min(1, "Name is required").optional(),
name: z
.string()
.trim()
.min(1, "Name is required")
.optional()
.transform(sanitizeFormulaInput),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
email: z.email().optional(),
username: z.string().trim().toLowerCase().min(3).max(100).optional(),
image: uploadedImageSchema.nullish(),
description: z.string().max(MAX_PARTNER_DESCRIPTION_LENGTH).nullish(),
description: z
.string()
.max(MAX_PARTNER_DESCRIPTION_LENGTH)
.nullish()
.transform(sanitizeFormulaInput),
profileType: z.enum(PartnerProfileType).optional(),
companyName: z.string().nullish(),
companyName: z.string().nullish().transform(sanitizeFormulaInput),
})
.extend(PartnerProfileDetailsSchema.partial().shape)
.transform((data) => ({
Expand Down
16 changes: 14 additions & 2 deletions apps/web/lib/zod/schemas/partners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,16 @@ const partnerImageSchema = z.union([
z.string().nullish(), // make image optional
]);

export const sanitizeFormulaInput = <T extends string | null | undefined>(
value: T,
): T => {
if (typeof value !== "string") {
return value;
}

return value.replace(/^[=+\-@\t\r]+/, "").trimStart() as T;
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

export const onboardPartnerSchema = createPartnerSchema
.omit({
username: true,
Expand All @@ -757,10 +767,12 @@ export const onboardPartnerSchema = createPartnerSchema
linkProps: true,
})
.extend({
name: z.string().min(1, "Name is required"),
name: z.string().min(1, "Name is required").transform(sanitizeFormulaInput),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
description:
createPartnerSchema.shape.description.transform(sanitizeFormulaInput),
image: partnerImageSchema,
profileType: z.enum(PartnerProfileType).default("individual"),
companyName: z.string().nullish(),
companyName: z.string().nullish().transform(sanitizeFormulaInput),
})
.refine(
(data) => {
Expand Down
Loading