Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chat.update allows to set message as empty string #34934

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changeset/nervous-maps-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/rest-typings": patch
---

Fixes `chat.update` endpoint, which allowed to update a message with an empty text. Now, the API will properly validate the message to contain at least one character.
16 changes: 16 additions & 0 deletions apps/meteor/tests/end-to-end/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,22 @@ describe('[Chat]', () => {
});
});

it('should fail if text is an empty string', async () => {
await request
.post(api('chat.update'))
.set(credentials)
.send({
roomId: testChannel._id,
msgId: message._id,
text: '',
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
});
});

it('should update a message successfully', (done) => {
void request
.post(api('chat.update'))
Expand Down
1 change: 1 addition & 0 deletions packages/rest-typings/src/v1/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ const ChatUpdateSchema = {
},
text: {
type: 'string',
minLength: 1,
},
previewUrls: {
type: 'array',
Expand Down
Loading