From 7bfe57e1a41a2c59583af3900cc8c1c1851facce Mon Sep 17 00:00:00 2001 From: kumburovicbranko682-boop Date: Sun, 28 Jun 2026 08:43:34 +0800 Subject: [PATCH] refactor(fileUtils.js): removefileatpath silently corrupts file tree when file not found (splice with index -1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the target file does not exist at the given path, `getChildFileFromName` returns `{index: -1, file: undefined}`. The destructured `index` is -1, and `currentFolder.splice(-1, 1)` silently removes the **last** item in the array instead of the intended file. This is silent data corruption — the user deletes a nonexistent path and loses an unrelated file. Affected files: fileUtils.js Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com> --- src/fileUtils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fileUtils.js b/src/fileUtils.js index 5ae7392b..e5eaf581 100644 --- a/src/fileUtils.js +++ b/src/fileUtils.js @@ -88,7 +88,9 @@ export function removeFileAtPath(files, path) { } // now we should be left with just one value in the pathPieces array - the actual file name const { index } = getChildFileFromName(currentFolder, pathPieces[0]); - currentFolder.splice(index, 1); + if (index !== -1) { + currentFolder.splice(index, 1); + } } /**