feat: Escape @room in the reply fallback when replying

This commit is contained in:
Sorunome 2021-03-09 13:41:00 +01:00
parent 3f2ced692f
commit 6d171542af
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 33 additions and 1 deletions

View File

@ -784,7 +784,10 @@ class Room {
.replaceAll('\n', '<br>'));
content['formatted_body'] =
'<mx-reply><blockquote><a href="https://matrix.to/#/${inReplyTo.room.id}/${inReplyTo.eventId}">In reply to</a> <a href="https://matrix.to/#/${inReplyTo.senderId}">${inReplyTo.senderId}</a><br>$replyHtml</blockquote></mx-reply>$repliedHtml';
content['body'] = replyText + "\n\n${content.tryGet<String>('body', '')}";
// We escape all @room-mentions here to prevent accidental room pings when an admin
// replies to a message containing that!
content['body'] =
'${replyText.replaceAll('@room', '@\u200broom')}\n\n${content.tryGet<String>('body', '')}';
content['m.relates_to'] = {
'm.in_reply_to': {
'event_id': inReplyTo.eventId,

View File

@ -499,6 +499,35 @@ void main() {
},
},
});
event = Event.fromJson({
'event_id': '\$replyEvent',
'content': {
'body': 'Hey @room',
'msgtype': 'm.text',
},
'type': 'm.room.message',
'sender': '@alice:example.org',
}, room);
FakeMatrixApi.calledEndpoints.clear();
resp = await room.sendTextEvent('Hello world',
txid: 'testtxid', inReplyTo: event);
expect(resp.startsWith('\$event'), true);
entry = FakeMatrixApi.calledEndpoints.entries
.firstWhere((p) => p.key.contains('/send/m.room.message/'));
content = json.decode(entry.value.first);
expect(content, {
'body': '> <@alice:example.org> Hey @\u{200b}room\n\nHello world',
'msgtype': 'm.text',
'format': 'org.matrix.custom.html',
'formatted_body':
'<mx-reply><blockquote><a href="https://matrix.to/#/!localpart:server.abc/\$replyEvent">In reply to</a> <a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a><br>Hey @room</blockquote></mx-reply>Hello world',
'm.relates_to': {
'm.in_reply_to': {
'event_id': '\$replyEvent',
},
},
});
});
test('send reaction', () async {