vfs: fix readlink, realpath and mkdtemp encoding - #66352
Open
christianaurichzm wants to merge 1 commit into
Open
christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
On a mounted VFS, `readlink()`, `realpath()` and `mkdtemp()` only
returned a Buffer for `{ encoding: 'buffer' }`. The string form
`'buffer'`, any other encoding, and a Buffer `mkdtemp()` prefix were
ignored. The `VirtualFileSystem` `readlink` and `realpath` methods
ignored the encoding with `MemoryProvider` and passed it on to
`RealFSProvider`, which threw `ERR_INVALID_ARG_TYPE` for `'buffer'`,
while for other encodings `realpath()` failed and `readlink()`
returned the host path of absolute targets.
Get these paths from the provider as strings and apply the encoding
to the result, normalizing the options with `getOptions()` and
converting with `encodeRealpathResult()` as `fs` does. The latter
moves to `internal/fs/utils` so the VFS can use it.
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66352 +/- ##
==========================================
- Coverage 90.36% 90.36% -0.01%
==========================================
Files 792 792
Lines 275386 275392 +6
Branches 52775 52773 -2
==========================================
+ Hits 248843 248848 +5
+ Misses 16979 16965 -14
- Partials 9564 9579 +15
🚀 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.
On a mounted VFS,
readlink(),realpath()andmkdtemp()only honor{ encoding: 'buffer' }. The string form'buffer'and other encodings like'hex'are ignored, and so is a Buffermkdtemp()prefix:With
RealFSProviderthe options are passed on to the hostfs, soreadlink()with'buffer'throwsERR_INVALID_ARG_TYPEandmyVfs.realpathSync(p, 'hex')fails withEACCES.The
VirtualFileSystemreadlinkandrealpathmethods now get a string from the provider and apply the encoding withgetOptions()andencodeRealpathResult(), asfsdoes. The helper moves fromlib/fs.jstointernal/fs/utils. Themkdtemphooks do the same, which replaces the per-hook Buffer conversions for these methods insetup.js.Since the VFS works with string paths, a
RealFSProviderlink target that isn't valid UTF-8 won't keep its bytes with'buffer'.readdir()has a similar gap, which I'll leave for a separate PR.The new test covers the sync, callback and promise variants on a memory and a real mount, and fails on main. The
test-vfs-*tests and thefsrealpath/readlink/mkdtemp tests pass on x64 Linux.