mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
fix: prevents blank messages from being posted to chat (#8257)
* fix: throws an error when the server receives a post chat request with a message containing only whitespace. * Adding a test confirming behavior around messages that only contain newlines. * Removing accidental only that was left on a test
This commit is contained in:
@@ -35,6 +35,24 @@ describe('POST /chat', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Returns an error when an empty message is provided', async () => {
|
||||||
|
await expect(user.post(`/groups/${groupWithChat._id}/chat`, { message: ' '}))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: t('invalidReqParams'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Returns an error when an message containing only newlines is provided', async () => {
|
||||||
|
await expect(user.post(`/groups/${groupWithChat._id}/chat`, { message: '\n\n'}))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: t('invalidReqParams'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Returns an error when group is not found', async () => {
|
it('Returns an error when group is not found', async () => {
|
||||||
await expect(user.post('/groups/invalidID/chat', { message: testMessage})).to.eventually.be.rejected.and.eql({
|
await expect(user.post('/groups/invalidID/chat', { message: testMessage})).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ api.postChat = {
|
|||||||
let chatUpdated;
|
let chatUpdated;
|
||||||
|
|
||||||
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
||||||
|
req.sanitize('message').trim();
|
||||||
req.checkBody('message', res.t('messageGroupChatBlankMessage')).notEmpty();
|
req.checkBody('message', res.t('messageGroupChatBlankMessage')).notEmpty();
|
||||||
|
|
||||||
let validationErrors = req.validationErrors();
|
let validationErrors = req.validationErrors();
|
||||||
|
|||||||
Reference in New Issue
Block a user