Skip to content

Commit 1144c5b

Browse files
fix: special character in mentioned user name causes crash (#2229)
1 parent 4449c1d commit 1144c5b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ const getMentionUsers = <
6161
}
6262
return acc;
6363
}, '');
64-
return mentionUserString;
64+
65+
// escape special characters
66+
return mentionUserString.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&');
6567
}
68+
6669
return '';
6770
};
6871

package/src/components/Message/MessageSimple/utils/renderText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const renderText = <
210210
if (userName) {
211211
acc += `${acc.length ? '|' : ''}@${userName}`;
212212
}
213-
return acc;
213+
return acc.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&');
214214
}, '')
215215
: '';
216216

0 commit comments

Comments
 (0)