From 59cd519337f9291af4cf35a4a403167bbea485f8 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 23 Jun 2025 18:53:40 +0200 Subject: [PATCH] fix(api): :bug: Fix error when masto-fe stupidly sends empty spoiler_text --- packages/api/routes/api/v1/statuses/index.test.ts | 14 ++++++++++++++ packages/client/schemas/status.ts | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/api/routes/api/v1/statuses/index.test.ts b/packages/api/routes/api/v1/statuses/index.test.ts index 1cc3535f..25572129 100644 --- a/packages/api/routes/api/v1/statuses/index.test.ts +++ b/packages/api/routes/api/v1/statuses/index.test.ts @@ -246,6 +246,20 @@ describe("/api/v1/statuses", () => { expect(ok3).toBe(false); }); + test("should work with an empty spoiler_text", async () => { + await using client = await generateClient(users[0]); + + const { data, ok } = await client.postStatus("Hello, world!", { + spoiler_text: "", + }); + + expect(ok).toBe(true); + expect(data).toMatchObject({ + content: "

Hello, world!

", + spoiler_text: "", + }); + }); + describe("mentions testing", () => { test("should correctly parse @mentions", async () => { await using client = await generateClient(users[0]); diff --git a/packages/client/schemas/status.ts b/packages/client/schemas/status.ts index 60623f1c..1165ebe5 100644 --- a/packages/client/schemas/status.ts +++ b/packages/client/schemas/status.ts @@ -58,7 +58,9 @@ export const StatusSource = z description: "The plain text used to compose the status.", example: "this is a status that will be edited", }), - spoiler_text: z.string().trim().min(1).max(1024).openapi({ + // min(0) because some masto-fe clients send empty spoiler_text + // when they don't want to set it. + spoiler_text: z.string().trim().min(0).max(1024).openapi({ description: "The plain text used to compose the status’s subject or content warning.", example: "",