Skip to content

Commit

Permalink
fix(MessageMentions): infinite loop in parsedUsers getter (#8430)
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed Aug 8, 2022
1 parent 5b053cf commit b8a3136
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/discord.js/src/structures/MessageMentions.js
Expand Up @@ -48,6 +48,14 @@ class MessageMentions {
*/
static GlobalChannelsPattern = new RegExp(this.ChannelsPattern.source, 'g');

/**
* A global regular expression variant of {@link MessageMentions.UsersPattern}.
* @type {RegExp}
* @memberof MessageMentions
* @private
*/
static GlobalUsersPattern = new RegExp(this.UsersPattern.source, 'g');

constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) {
/**
* The client the message is from
Expand Down Expand Up @@ -225,7 +233,7 @@ class MessageMentions {
if (this._parsedUsers) return this._parsedUsers;
this._parsedUsers = new Collection();
let matches;
while ((matches = this.constructor.UsersPattern.exec(this._content)) !== null) {
while ((matches = this.constructor.GlobalUsersPattern.exec(this._content)) !== null) {
const user = this.client.users.cache.get(matches[1]);
if (user) this._parsedUsers.set(user.id, user);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/typings/index.d.ts
Expand Up @@ -1881,8 +1881,9 @@ export class MessageMentions {
public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>;
public toJSON(): unknown;

public static ChannelsPattern: typeof FormattingPatterns.Channel;
private static GlobalChannelsPattern: RegExp;
private static GlobalUsersPattern: RegExp;
public static ChannelsPattern: typeof FormattingPatterns.Channel;
public static EveryonePattern: RegExp;
public static RolesPattern: typeof FormattingPatterns.Role;
public static UsersPattern: typeof FormattingPatterns.User;
Expand Down

0 comments on commit b8a3136

Please sign in to comment.