From a0b4b5f61a956173c114c73b160f6c987f0acec4 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Thu, 20 Jun 2024 11:38:04 +0200 Subject: [PATCH] Fix: the emojis import function could add more entries than max allowed emoji count. + another minor fix. --- CHANGELOG.md | 1 + client/@types/global.d.ts | 1 + .../common/configuration/services/channel-details.ts | 12 +++++++++++- languages/en.yml | 1 + languages/fr.yml | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 568811c7..ef754363 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 10.1.1 (Not released yet) * #436: Saving emojis per batch, to avoid hitting max payload limit. +* Fix: the emojis import function could add more entries than max allowed emoji count. ## 10.1.0 diff --git a/client/@types/global.d.ts b/client/@types/global.d.ts index dd200ec7..1f15b839 100644 --- a/client/@types/global.d.ts +++ b/client/@types/global.d.ts @@ -83,6 +83,7 @@ declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_NICKNAME: string declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FOR_MORE_INFO: string declare const LOC_VALIDATION_ERROR: string +declare const LOC_TOO_MANY_ENTRIES: string declare const LOC_INVALID_VALUE: string declare const LOC_INVALID_VALUE_MISSING: string declare const LOC_INVALID_VALUE_WRONG_TYPE: string diff --git a/client/common/configuration/services/channel-details.ts b/client/common/configuration/services/channel-details.ts index 39f1dc7f..d280c235 100644 --- a/client/common/configuration/services/channel-details.ts +++ b/client/common/configuration/services/channel-details.ts @@ -181,6 +181,16 @@ export class ChannelDetailsService { public async validateEmojisConfiguration (channelEmojis: ChannelEmojis): Promise { const propertiesError: ValidationError['properties'] = {} + if (channelEmojis.customEmojis.length > maxEmojisPerChannel) { + // This can happen when using the import function. + const validationError = new ValidationError( + 'ChannelEmojisValidationError', + await this._registerClientOptions.peertubeHelpers.translate(LOC_TOO_MANY_ENTRIES), + propertiesError + ) + throw validationError + } + const seen = new Map() for (const [i, e] of channelEmojis.customEmojis.entries()) { propertiesError[`emojis.${i}.sn`] = [] @@ -233,7 +243,7 @@ export class ChannelDetailsService { let watchDog = 0 while (i >= 0) { watchDog++ - if (watchDog > maxEmojisPerChannel + 10) { // just to avoid infinite loop + if (watchDog > channelEmojis.customEmojis.length + 10) { // just to avoid infinite loop throw new Error('Seems we have sent too many emojis, this was not expected') } const data: CustomEmojiDefinition[] = customEmojis.slice(0, i + 1) // all elements until first new file diff --git a/languages/en.yml b/languages/en.yml index 3e7dea32..38f3cb50 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -455,6 +455,7 @@ invalid_value_wrong_format: "Value is in the wrong format." invalid_value_not_in_range: "Value is not in authorized range." invalid_value_file_too_big: "File size is too big (max size: %s)." invalid_value_duplicate: "Duplicate value" +too_many_entries: "Too many entries" slow_mode_info: "Slow mode is enabled, users can send a message every %1$s seconds." diff --git a/languages/fr.yml b/languages/fr.yml index 11a73280..eab63f8d 100644 --- a/languages/fr.yml +++ b/languages/fr.yml @@ -522,3 +522,4 @@ livechat_token_disabled_description: "Les utilisateur⋅rices peuvent générer pour inclure le tchat dans les docks web dans OBS.\nConsultez la documentation pour plus d'informations.\nVous pouvez désactiver cette fonctionnalité en cochant ce paramètre.\n" +too_many_entries: "Trop d'entrées"