Skip to content

Commit 4b12c2a

Browse files
committed
Better handling of usernames with spaces
1 parent a62f06a commit 4b12c2a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/Chat.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ const useStyles = makeStyles((theme) => ({
8383
}));
8484

8585
const makeMentionRE = (username) => {
86-
username = username.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
87-
username = username.replace(/^anonymous /i, "($&)?");
88-
return new RegExp(`@(all|${username})(\\W|$)`, "iu");
86+
username = username.toLowerCase().replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
87+
var anon = "";
88+
const anonIdx = username.indexOf("anonymous ");
89+
if (anonIdx !== -1) {
90+
anon = `(${username.slice(0, anonIdx + 10)})?`;
91+
username = username.slice(anonIdx + 10);
92+
}
93+
const parts = username.split(/\s+/).filter((s) => s);
94+
return new RegExp(`(\\W|^)@(all|${anon}(${parts.join("|")}))(\\W|$)`, "iu");
8995
};
9096

9197
const emojiRE = /:([a-z0-9_+-]+):/g;

0 commit comments

Comments
 (0)