Repository navigation
fs: fix mkdtempDisposable with Buffer paths - #66594
Open
gengjiawen wants to merge 1 commit into
Open
gengjiawen wants to merge 1 commit into
gengjiawen wants to merge 1 commit into
Conversation
fs.mkdtempDisposableSync() and fsPromises.mkdtempDisposable() pass the path of the new directory to path.resolve(), which only accepts strings. When that path is a Buffer, because the prefix is a Buffer or `encoding` is 'buffer', both throw ERR_INVALID_ARG_TYPE after the directory has been created, and nothing removes it. On Windows, resolve a Buffer path as UTF-8 so win32 semantics stay intact. On POSIX, keep an absolute Buffer as created and prepend the cwd captured at creation to a relative one, so bytes that are not valid UTF-8 are preserved. Fixes: nodejs#66593 Refs: nodejs#64397 Signed-off-by: Jiawen Geng <technicalcute@gmail.com> Assisted-by: claude:opus-5.5 Assisted-by: grok-4.7
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66594 +/- ##
==========================================
- Coverage 90.44% 90.44% -0.01%
==========================================
Files 791 791
Lines 276562 276592 +30
Branches 53126 53125 -1
==========================================
+ Hits 250130 250154 +24
+ Misses 16846 16841 -5
- Partials 9586 9597 +11
🚀 New features to boost your workflow:
|
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.
fs.mkdtempDisposableSync()andfsPromises.mkdtempDisposable()resolve the path of the new directory withpath.resolve(), so thatremove()still works afterprocess.chdir().path.resolve()only accepts strings, so when the path is a Buffer (a Buffer prefix, orencoding: 'buffer'), both functions throwERR_INVALID_ARG_TYPEafter the directory has been created, and the directory is never removed.absoluteMkdtempPath()ininternal/fs/utilsstashes that path forremove():path.resolve()and encoded back. Root-relative (\foo) and drive-relative (D:foo) prefixes keep win32 semantics, and non-ASCII characters in the cwd stay intactjoin()used for other string-plus-Buffer pathsThe tests cover both the sync and the promise API: a Buffer prefix,
encoding: 'buffer', a relative Buffer prefix followed byprocess.chdir(), a relative Buffer prefix in a non-ASCII directory, on Linux a prefix containing a byte that is not valid UTF-8, and on POSIX a..component after a symlink, soremove()deletes the directory the OS actually created.Fixes: #66593
Refs: #64397
AI disclosure: written with the help of Claude (claude:opus-5.5) and Grok (grok-4.7). I checked the bug against the source and the latest nightly, and reviewed the fix and tests.