Repository navigation
fs: normalize dot segments in rm and rmSync - #66673
Open
RohithPariki wants to merge 1 commit into
Open
RohithPariki wants to merge 1 commit into
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>
Contributor
|
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. |
This was referenced Oct 12, 2026
Contributor
|
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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