1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Merge pull request #1628 from matrix-org/jryans/opt-display-name

Extract display name patterns to constants
This commit is contained in:
J. Ryan Stinnett
2021-03-03 11:44:30 +00:00
committed by GitHub

View File

@@ -290,6 +290,9 @@ RoomMember.prototype.getMxcAvatarUrl = function() {
return null; return null;
}; };
const MXID_PATTERN = /@.+:.+/;
const LTR_RTL_PATTERN = /[\u200E\u200F\u202A-\u202F]/;
function calculateDisplayName(selfUserId, displayName, roomState) { function calculateDisplayName(selfUserId, displayName, roomState) {
if (!displayName || displayName === selfUserId) { if (!displayName || displayName === selfUserId) {
return selfUserId; return selfUserId;
@@ -308,13 +311,13 @@ function calculateDisplayName(selfUserId, displayName, roomState) {
// Next check if the name contains something that look like a mxid // Next check if the name contains something that look like a mxid
// If it does, it may be someone trying to impersonate someone else // If it does, it may be someone trying to impersonate someone else
// Show full mxid in this case // Show full mxid in this case
let disambiguate = /@.+:.+/.test(displayName); let disambiguate = MXID_PATTERN.test(displayName);
if (!disambiguate) { if (!disambiguate) {
// Also show mxid if the display name contains any LTR/RTL characters as these // Also show mxid if the display name contains any LTR/RTL characters as these
// make it very difficult for us to find similar *looking* display names // make it very difficult for us to find similar *looking* display names
// E.g "Mark" could be cloned by writing "kraM" but in RTL. // E.g "Mark" could be cloned by writing "kraM" but in RTL.
disambiguate = /[\u200E\u200F\u202A-\u202F]/.test(displayName); disambiguate = LTR_RTL_PATTERN.test(displayName);
} }
if (!disambiguate) { if (!disambiguate) {