From 63205a73e8ededd56c2a801e51dd922a0943673c Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Thu, 20 May 2021 11:44:04 +0200 Subject: [PATCH] Improve `truncateFileName` logic for edge cases --- chrome/content/zotero/xpcom/file.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 9fe1133b66..96e6296b43 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -1230,6 +1230,12 @@ Zotero.File = new function(){ ext = '.' + ext; } + if (ext.length >= maxLength) { + // Improve resulting truncated filename by dropping extension if it wouldn't fit within + // the limit. e.g. for (lorem.json, 5) it returns "lorem", instead of ".json" + ext = ''; + } + return fn.substr(0,maxLength-ext.length) + ext; }