chinchang / chinchang/web-maker

fix(fileUtils.js): removefileatpath silently corrupts file tree when file not found (splice with index -1)

Open Beginner friendly
#605 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.7k
Forks
323
PR merge metrics
No merged PRs in 30d

Description

## Description

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.

**Severity**: `critical`
**File**: `src/fileUtils.js`

## Expected Behavior

The code should handle this case properly to avoid unexpected errors or degraded quality.

Contributor guide

Open the contributing guide

Research direction

Start in src/fileUtils.js at getChildFileFromName and the currentFolder.splice call, then reproduce removal of a nonexistent path. Done means the missing target no longer removes an unrelated file and the case is handled without silent corruption; check the existing file-utility test setup if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.