From d091bf9611438f38b4b3ff693b86cb2bf873145c Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Thu, 30 May 2024 17:14:39 -0300 Subject: [PATCH] Fix: formatFileName function cant truncate when numberToTruncate are bigger than name length --- .../chatView/filePreviewChat/utils/format-file-name.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx b/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx index fada2ef59..7805a53ce 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx @@ -2,6 +2,9 @@ export default function formatFileName( name: string, numberToTruncate: number = 29, ): string { + if (name[numberToTruncate] === undefined) { + return name; + } const fileExtension = name.split(".").pop(); // Get the file extension const baseName = name.slice(0, name.lastIndexOf(".")); // Get the base name without the extension if (baseName.length > 6) {