fix: prevent body (and plaintextBody) from return html by accident
It is not clear why we ever would want to return the formatted_body when we ask for the body, but it seems to not be used anywhere and there are no tests covering that functionality. However it leads to suprising results, where the plaintextBody can be tricked into returning html without applying conversions. So we just get rid of that functionality.
This commit is contained in:
parent
9ebd2e3893
commit
c7d49695d5
|
|
@ -292,7 +292,6 @@ class Event extends MatrixEvent {
|
||||||
String get body {
|
String get body {
|
||||||
if (redacted) return 'Redacted';
|
if (redacted) return 'Redacted';
|
||||||
if (text != '') return text;
|
if (text != '') return text;
|
||||||
if (formattedText != '') return formattedText;
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1200,6 +1200,35 @@ void main() {
|
||||||
}, room);
|
}, room);
|
||||||
expect(event.plaintextBody, '**blah**');
|
expect(event.plaintextBody, '**blah**');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('body', () {
|
||||||
|
final event = Event.fromJson({
|
||||||
|
'type': EventTypes.Message,
|
||||||
|
'content': {
|
||||||
|
'body': 'blah',
|
||||||
|
'msgtype': 'm.text',
|
||||||
|
'format': 'org.matrix.custom.html',
|
||||||
|
'formatted_body': '<b>blub</b>',
|
||||||
|
},
|
||||||
|
'event_id': '\$source',
|
||||||
|
'sender': '@alice:example.org',
|
||||||
|
}, room);
|
||||||
|
expect(event.body, 'blah');
|
||||||
|
|
||||||
|
final event2 = Event.fromJson({
|
||||||
|
'type': EventTypes.Message,
|
||||||
|
'content': {
|
||||||
|
'body': '',
|
||||||
|
'msgtype': 'm.text',
|
||||||
|
'format': 'org.matrix.custom.html',
|
||||||
|
'formatted_body': '<b>blub</b>',
|
||||||
|
},
|
||||||
|
'event_id': '\$source',
|
||||||
|
'sender': '@alice:example.org',
|
||||||
|
}, room);
|
||||||
|
expect(event2.body, 'm.room.message');
|
||||||
|
});
|
||||||
|
|
||||||
test('getDisplayEvent', () {
|
test('getDisplayEvent', () {
|
||||||
final room = Room(id: '!1234', client: client);
|
final room = Room(id: '!1234', client: client);
|
||||||
var event = Event.fromJson({
|
var event = Event.fromJson({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue