Repository navigation
fs: normalize dot segments in rm and rmSync - #66673
RohithPariki wants to merge 1 commit into
Conversation
When paths containing relative components (such as '.' or '..') are passed to fs.rm(), fs.rmSync(), or fs.promises.rm(), the different underlying implementations (native binding.rmSync vs JS rimraf) can produce divergent results or silent deletion failures because paths were used as-is without canonicalization. Add normalizePathForRm to resolve dot-segment components for both string and Buffer inputs using byte-safe latin1 preservation before reaching the underlying deletion routines. Fixes: nodejs#61958 Signed-off-by: Rohith Pariki <rohithpariki@gmail.com>
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
|
You have an open unapproved PR #66471 and so you have already reached the limit of 1 open unapproved PR for a "first-time contributor". The recommendations in: advise you should tackle only one issue at a time and that you should not open any new PRs until your first PR has been approved. You already acknowledged this rule in #66472 (comment) |
|
Tests are failing in GitHub Actions CI. |
|
Converting to draft as tests are failing, and there is another unapproved PR #66471 open under this user's name. |
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
fs
Description of change
When paths containing relative dot segments (such as
.or..) are passed tofs.rm(),fs.rmSync(), orfs.promises.rm(), the different underlying implementations (binding.rmSyncviastd::filesystem::remove_allvs JavaScriptrimraf) produce divergent results:rimraf, child paths are constructed by concatenating onto the unresolved path. When recursion removes intermediate directory components, subsequent calls fail withENOENT, whichrimraftreats as "already deleted," causing silent partial removals.rmSyncthrows an error without a.codeproperty on paths with trailing/..This PR normalizes dot segments before reaching the underlying removal routines:
normalizePathForRm()inlib/fs.jsandlib/internal/fs/promises.js.Bufferinputs: forBufferpaths, binary byte content is preserved 1:1 usinglatin1round-tripping before and after normalization to prevent data corruption on non-UTF-8 paths.URLinputs are converted to strings viagetValidatedPath()before normalization.Tests
Added regression tests in
test/parallel/test-fs-rm.jscovering:a/b/../.,a/b/..,a/.,a/b/c/.,a/b/c/../..,a/b/c/d/../../..,a/b/.././b,./a) acrossfs.rmSync,fs.rm(callback), andfs.promises.rm.Fixes: #61958