address unneeded defensive code lint

IMHO this check is actually necessary, as we do call the function with an empty argument. So we need a guard there, but we could simplify it a bit, by making the argument an empty array by default. I still kept the check for undefined (line 3249, first check) in case the caller passes us an undefined variable.

See: https://github.com/PrivateBin/PrivateBin/security/quality/rules/js%2Funneeded-defensive-code - Copilot suggested to simply remove the if-condition and its else block, which I think is wrong.
This commit is contained in:
El RIDO
2026-01-25 09:26:14 +01:00
parent 7806faf16c
commit 0ed48c455f
2 changed files with 7 additions and 7 deletions

View File

@@ -3234,7 +3234,7 @@ jQuery.PrivateBin = (function($) {
* @param {FileList[]} loadedFiles (optional) loaded files array
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader#readAsDataURL()}
*/
function readFileData(loadedFiles) {
function readFileData(loadedFiles = []) {
// Clear old cache
me.removeAttachmentData();
@@ -3246,15 +3246,15 @@ jQuery.PrivateBin = (function($) {
return;
}
if (loadedFiles === undefined) {
loadedFiles = [...$fileInput[0].files];
me.clearDragAndDrop();
} else {
if (loadedFiles && loadedFiles.length > 0) {
const fileNames = loadedFiles.map((loadedFile => loadedFile.name));
printDragAndDropFileNames(fileNames);
} else {
loadedFiles = [...$fileInput[0].files];
me.clearDragAndDrop();
}
if (typeof loadedFiles !== 'undefined') {
if (loadedFiles.length > 0) {
files = loadedFiles;
loadedFiles.forEach((loadedFile, index) => {
const fileReader = new FileReader();