fix(timeline): guard per-message-profile emote stripping against missing bodies

Fixes SABLE-1T0
This commit is contained in:
Erwan Leboucher committed 2026-09-11 12:09:03 +02:00
1 parent cea097b29d
commit fa608f806a
3 files changed
+20 -4

No files matched your search

@@ -222,4 +222,14 @@ describe('RenderMessageContent', () => {
expect(screen.getByTestId('poll-event')).toBeInTheDocument();
});
it('renders a per-message profile emote without a formatted body', () => {
renderMessageWithContent({
msgtype: MsgType.Emote,
body: 'Bob: waves',
'com.beeper.per_message_profile': { id: 'bob', displayname: 'Bob' },
});
expect(screen.getByText('waves')).toBeInTheDocument();
});
});
+6 -2
View File
@@ -449,8 +449,12 @@ function RenderMessageContentInternal({
const strippedContent = pmp
? {
...content,
formatted_body: stripPerMessageProfileFormattedBody(content['formatted_body'] as string),
body: stripPerMessageProfilePlainBody(content['body'] as string),
...(typeof content['formatted_body'] === 'string'
? { formatted_body: stripPerMessageProfileFormattedBody(content['formatted_body']) }
: {}),
...(typeof content['body'] === 'string'
? { body: stripPerMessageProfilePlainBody(content['body']) }
: {}),
}
: content;
+4 -2
View File
@@ -123,6 +123,8 @@ export function stripPerMessageProfilePlainBody(formatted_body: string, profile?
return formatted_body.replace(/^.*?: /, '');
}
export function stripPerMessageProfileFormattedBody(formatted_body: string): string {
return formatted_body.replace(/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/, '');
export function stripPerMessageProfileFormattedBody(
formatted_body: string | undefined
): string | undefined {
return formatted_body?.replace(/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/, '');
}