From 6cb6dd3bb560d4b5898f99cb9bd14055055cf933 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 1 Aug 2024 10:30:21 -0400 Subject: [PATCH] File renaming: Fix empty value being added when all types are disabled And filter out empty values in isRenameAllowedForType() in order to handle bad pref values set before this commit. Follow-up to aab90527ecdd91c75e91694c6f50e4fdb646b366 --- chrome/content/zotero/preferences/preferences_general.js | 6 +++++- chrome/content/zotero/xpcom/attachments.js | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/preferences/preferences_general.js b/chrome/content/zotero/preferences/preferences_general.js index 717688e1f4..b6cd907367 100644 --- a/chrome/content/zotero/preferences/preferences_general.js +++ b/chrome/content/zotero/preferences/preferences_general.js @@ -219,7 +219,11 @@ Zotero_Preferences.General = { setAutoRenameFileTypes: function () { let typesBox = document.getElementById('zotero-prefpane-file-renaming-file-types-box'); - let enabledTypes = new Set(Zotero.Prefs.get('autoRenameFiles.fileTypes').split(',')); + let enabledTypes = new Set( + Zotero.Prefs.get('autoRenameFiles.fileTypes') + .split(',') + .filter(Boolean) + ); for (let checkbox of typesBox.querySelectorAll('checkbox')) { if (checkbox.checked) { enabledTypes.add(checkbox.dataset.contentType); diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index e2e09b99e3..5e9d1c9f9d 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -2479,9 +2479,9 @@ Zotero.Attachments = new function () { this.isRenameAllowedForType = function (contentType) { let typePrefixes; try { - let prefValue = Zotero.Prefs.get('autoRenameFiles.fileTypes'); - if (!prefValue) return false; - typePrefixes = prefValue.split(','); + typePrefixes = Zotero.Prefs.get('autoRenameFiles.fileTypes') + .split(',') + .filter(Boolean); } catch (e) { typePrefixes = [];