Improve truncateFileName logic for edge cases

This commit is contained in:
Tom Najdek 2021-05-20 11:44:04 +02:00
parent 89d81cee41
commit 63205a73e8
No known key found for this signature in database
GPG key ID: EEC61A7B4C667D77

View file

@ -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;
}