Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(status): reject an empty or blank text status body

Yudhi Armyndharis29de23486009
diff --git a/src/modules/status/dto/send-text-status.dto.spec.ts b/src/modules/status/dto/send-text-status.dto.spec.ts
index 8a06e27b0..dd0c18a99 100644
--- a/src/modules/status/dto/send-text-status.dto.spec.ts
+++ b/src/modules/status/dto/send-text-status.dto.spec.ts
@@ -68,3 +68,16 @@ describe('SendTextStatusDto recipients validation', () => {
expect(errors).toHaveLength(0);
});
});
+
+describe('SendTextStatusDto text validation', () => {
+ it('rejects an empty or whitespace-only body', async () => {
+ for (const text of ['', ' ', '\n\t']) {
+ const errors = await validate(plainToInstance(SendTextStatusDto, { text }));
+ expect(errors.some(e => e.property === 'text')).toBe(true);
+ }
+ });
+
+ it('accepts a body with surrounding whitespace', async () => {
+ expect(await validate(plainToInstance(SendTextStatusDto, { text: ' hi ' }))).toHaveLength(0);
+ });
+});
diff --git a/src/modules/status/dto/send-text-status.dto.ts b/src/modules/status/dto/send-text-status.dto.ts
index e47c12b78..6a09825d4 100644
--- a/src/modules/status/dto/send-text-status.dto.ts
+++ b/src/modules/status/dto/send-text-status.dto.ts
@@ -3,8 +3,15 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ToStrictNumber } from '../../../common/utils/strict-boolean';
export class SendTextStatusDto {
- @ApiProperty({ description: 'Status text body.', example: 'Out for delivery 📦', maxLength: 4096 })
+ @ApiProperty({
+ description: 'Status text body. Must contain a non-whitespace character.',
+ example: 'Out for delivery 📦',
+ minLength: 1,
+ maxLength: 4096,
+ })
@IsString()
+ // A blank body would publish an empty story (Baileys) or fail inside the engine with a 500.
+ @Matches(/\S/, { message: 'text must not be blank' })
@MaxLength(4096)
text!: string;