From b8a31360a220e3d796f5381bd215d30a379ecb7c Mon Sep 17 00:00:00 2001 From: Almeida Date: Mon, 8 Aug 2022 10:10:32 +0100 Subject: [PATCH] fix(MessageMentions): infinite loop in `parsedUsers` getter (#8430) --- packages/discord.js/src/structures/MessageMentions.js | 10 +++++++++- packages/discord.js/typings/index.d.ts | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/MessageMentions.js b/packages/discord.js/src/structures/MessageMentions.js index b142a6c68373..a07e77fb5d70 100644 --- a/packages/discord.js/src/structures/MessageMentions.js +++ b/packages/discord.js/src/structures/MessageMentions.js @@ -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 @@ -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); } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index cd8fe8804c62..617e96c90fc4 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1881,8 +1881,9 @@ export class MessageMentions { public crosspostedChannels: Collection; 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;