From 30ea8910bef1a8b2afa7a2429098d2e377b3fe4f Mon Sep 17 00:00:00 2001 From: harimambura Date: Sat, 25 Jun 2022 14:37:08 +0400 Subject: [PATCH] Fix calculating button absolute path length Fix calculating button absolute path length with non-Latin symbols according issue https://github.com/EdJoPaTo/grammy-inline-menu/issues/183 --- source/keyboard.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/keyboard.ts b/source/keyboard.ts index c78d7a9..1a79b9b 100644 --- a/source/keyboard.ts +++ b/source/keyboard.ts @@ -78,8 +78,9 @@ function renderRow(templates: readonly ButtonTemplate[], path: string): readonly function renderCallbackButtonTemplate(template: CallbackButtonTemplate, path: string): InlineKeyboardButton { const absolutePath = combinePath(path, template.relativePath) - if (absolutePath.length > 64) { - throw new Error(`callback_data only supports 1-64 bytes. With this button (${template.relativePath}) it would get too long (${absolutePath.length}). Full path: ${absolutePath}`) + const absolutePathLength = Buffer.byteLength(absolutePath, 'utf-8') + if (absolutePathLength > 64) { + throw new Error(`callback_data only supports 1-64 bytes. With this button (${template.relativePath}) it would get too long (${absolutePathLength}). Full path: ${absolutePath}`) } return {