From d83c01af6ca380a5463c0d85941affff2f28e541 Mon Sep 17 00:00:00 2001 From: zyoshoka Date: Thu, 11 Jan 2024 22:50:21 +0900 Subject: [PATCH] fix(backend): prohibit posting whitespace-only notes --- .../backend/src/server/api/endpoints/notes/create.test.ts | 5 +++++ packages/backend/src/server/api/endpoints/notes/create.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/packages/backend/src/server/api/endpoints/notes/create.test.ts b/packages/backend/src/server/api/endpoints/notes/create.test.ts index 0aa05a2c93..3228bbd014 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.test.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.test.ts @@ -48,6 +48,11 @@ describe('api:notes/create', () => { expect(v({ text: await tooLong })) .toBe(INVALID); }); + + test('whitespace-only post', () => { + expect(v({ text: ' ' })) + .toBe(INVALID); + }); }); describe('cw', () => { diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts index 52a32b7fec..ed522e03c9 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.ts @@ -138,6 +138,7 @@ export const paramDef = { minLength: 1, maxLength: MAX_NOTE_TEXT_LENGTH, nullable: true, + pattern: '[^\\s]+', }, fileIds: { type: 'array', @@ -195,6 +196,7 @@ export const paramDef = { minLength: 1, maxLength: MAX_NOTE_TEXT_LENGTH, nullable: false, + pattern: '[^\\s]+', }, }, required: ['text'],