mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-30 13:52:44 -08:00
fix(timeline): guard per-message-profile emote stripping against missing bodies
Fixes SABLE-1T0
This commit is contained in:
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();
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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>/, '');
|
||||
}
|
||||
Reference in new issue
Block a user