Skip to content

Commit 0de9318

Browse files
authored
fix: parseUrls parameter not working in chat.postMessage (RocketChat#36265)
1 parent 95072bb commit 0de9318

4 files changed

Lines changed: 68 additions & 2 deletions

File tree

.changeset/nervous-mugs-destroy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/rest-typings': patch
3+
'@rocket.chat/meteor': patch
4+
---
5+
6+
Fixes an issue where chat.postMessage returned an error when using the parseUrls flag.

apps/meteor/tests/data/api-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import supertest from 'supertest';
55

66
import { adminUsername, adminPassword } from './user';
77

8-
const apiUrl = process.env.TEST_API_URL || 'http://localhost:3000';
8+
export const apiUrl = process.env.TEST_API_URL || 'http://localhost:3000';
99

1010
export const request = supertest(apiUrl);
1111
const prefix = '/api/v1/';

apps/meteor/tests/end-to-end/api/chat.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { expect } from 'chai';
55
import { after, before, beforeEach, describe, it } from 'mocha';
66
import type { Response } from 'supertest';
77

8-
import { getCredentials, api, request, credentials } from '../../data/api-data';
8+
import { getCredentials, api, request, credentials, apiUrl } from '../../data/api-data';
99
import { followMessage, sendSimpleMessage, deleteMessage } from '../../data/chat.helper';
1010
import { imgURL } from '../../data/interactions';
1111
import { updatePermission, updateSetting } from '../../data/permissions.helper';
@@ -515,6 +515,60 @@ describe('[Chat]', () => {
515515
.end(done);
516516
});
517517

518+
it('should not parse urls when parseUrls=false is provided', async () => {
519+
return request
520+
.post(api('chat.postMessage'))
521+
.set(credentials)
522+
.send({
523+
channel: testChannel.name,
524+
text: apiUrl,
525+
parseUrls: false,
526+
})
527+
.expect('Content-Type', 'application/json')
528+
.expect(200)
529+
.expect((res) => {
530+
expect(res.body).to.have.property('success', true);
531+
expect(res.body).to.have.nested.property('message.msg', apiUrl);
532+
expect(res.body.message).to.not.have.property('urls');
533+
});
534+
});
535+
536+
it('should parse urls when parseUrls=true is provided', async () => {
537+
return request
538+
.post(api('chat.postMessage'))
539+
.set(credentials)
540+
.send({
541+
channel: testChannel.name,
542+
text: apiUrl,
543+
parseUrls: true,
544+
})
545+
.expect('Content-Type', 'application/json')
546+
.expect(200)
547+
.expect((res) => {
548+
expect(res.body).to.have.property('success', true);
549+
expect(res.body).to.have.nested.property('message.msg', apiUrl);
550+
expect(res.body.message).to.have.property('urls');
551+
});
552+
});
553+
554+
it('should parse urls when parseUrls is not provided', async () => {
555+
return request
556+
.post(api('chat.postMessage'))
557+
.set(credentials)
558+
.send({
559+
channel: testChannel.name,
560+
text: apiUrl,
561+
parseUrls: undefined,
562+
})
563+
.expect('Content-Type', 'application/json')
564+
.expect(200)
565+
.expect((res) => {
566+
expect(res.body).to.have.property('success', true);
567+
expect(res.body).to.have.nested.property('message.msg', apiUrl);
568+
expect(res.body.message).to.have.property('urls');
569+
});
570+
});
571+
518572
describe('text message allowed size', () => {
519573
before(async () => {
520574
await updateSetting('Message_MaxAllowedSize', 10);

packages/rest-typings/src/v1/chat.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,9 @@ const ChatPostMessageSchema = {
830830
type: 'object',
831831
nullable: true,
832832
},
833+
parseUrls: {
834+
type: 'boolean',
835+
},
833836
},
834837
required: ['roomId'],
835838
additionalProperties: false,
@@ -875,6 +878,9 @@ const ChatPostMessageSchema = {
875878
type: 'object',
876879
nullable: true,
877880
},
881+
parseUrls: {
882+
type: 'boolean',
883+
},
878884
},
879885
required: ['channel'],
880886
additionalProperties: false,

0 commit comments

Comments
 (0)