Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Trim user input (#2008)

Luke Vella6628d136df68
diff --git a/apps/web/src/components/create-poll.tsx b/apps/web/src/components/create-poll.tsx
index c01b99a28..a59962e18 100644
--- a/apps/web/src/components/create-poll.tsx
+++ b/apps/web/src/components/create-poll.tsx
@@ -73,13 +73,13 @@ export const CreatePoll: React.FunctionComponent = () => {
<Form {...form}>
<form
onSubmit={form.handleSubmit(async (formData) => {
- const title = required(formData?.title);
+ const title = required(formData?.title.trim());
await createGuestIfNeeded();
await createPoll.mutateAsync(
{
title: title,
- location: formData?.location,
- description: formData?.description,
+ location: formData?.location?.trim(),
+ description: formData?.description?.trim(),
timeZone: formData?.timeZone,
hideParticipants: formData?.hideParticipants,
disableComments: formData?.disableComments,
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index ba3048891..320022b3b 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -171,8 +171,8 @@ export const polls = router({
z.object({
title: z.string().trim().min(1),
timeZone: z.string().optional(),
- location: z.string().optional(),
- description: z.string().optional(),
+ location: z.string().trim().optional(),
+ description: z.string().trim().optional(),
hideParticipants: z.boolean().optional(),
hideScores: z.boolean().optional(),
disableComments: z.boolean().optional(),
@@ -211,6 +211,9 @@ export const polls = router({
return next();
})
.mutation(async ({ ctx, input }) => {
+ const title = input.title;
+ const location = input.location || undefined;
+ const description = input.description || undefined;
const adminToken = nanoid();
const participantUrlId = nanoid();
const pollId = nanoid();
@@ -237,10 +240,10 @@ export const polls = router({
},
data: {
id: pollId,
- title: input.title,
+ title,
timeZone: input.timeZone,
- location: input.location,
- description: input.description,
+ location,
+ description,
adminUrlId: adminToken,
participantUrlId,
...(ctx.user.isLegacyGuest
@@ -307,8 +310,8 @@ export const polls = router({
properties: {
title: poll.title,
optionCount: poll.options.length,
- hasLocation: !!input.location,
- hasDescription: !!input.description,
+ hasLocation: !!location,
+ hasDescription: !!description,
timezone: input.timeZone,
disableCommnets: poll.disableComments,
hideParticipants: poll.hideParticipants,
@@ -326,10 +329,10 @@ export const polls = router({
.input(
z.object({
urlId: z.string(),
- title: z.string().optional(),
+ title: z.string().trim().optional(),
timeZone: z.string().optional(),
- location: z.string().optional(),
- description: z.string().optional(),
+ location: z.string().trim().optional(),
+ description: z.string().trim().optional(),
optionsToDelete: z.string().array().optional(),
optionsToAdd: z.string().array().optional(),
hideParticipants: z.boolean().optional(),
diff --git a/apps/web/src/trpc/routers/polls/comments.ts b/apps/web/src/trpc/routers/polls/comments.ts
index 6f69e6c5d..4fbeaf980 100644
--- a/apps/web/src/trpc/routers/polls/comments.ts
+++ b/apps/web/src/trpc/routers/polls/comments.ts
@@ -76,8 +76,8 @@ export const comments = router({
.input(
z.object({
pollId: z.string(),
- authorName: z.string(),
- content: z.string(),
+ authorName: z.string().trim().min(1),
+ content: z.string().trim().min(1),
}),
)
.mutation(async ({ ctx, input: { pollId, authorName, content } }) => {
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index 2890a900d..9b94fbb99 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -139,7 +139,7 @@ export const participants = router({
.input(
z.object({
pollId: z.string(),
- name: z.string().min(1, "Participant name is required").max(100),
+ name: z.string().trim().min(1, "Participant name is required").max(100),
email: z.string().optional(),
timeZone: z.string().optional(),
votes: z