GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — vfs: fix readlink, realpath and mkdtemp encoding by christianaurichzm · Pull Request #66352 · nodejs/node

Conversation

@christianaurichzm

@christianaurichzm christianaurichzm commented Sep 27, 2026

Copy link
Copy Markdown
Member

On a mounted VFS, readlink(), realpath() and mkdtemp() only honor { encoding: 'buffer' }. The string form 'buffer' and other encodings like 'hex' are ignored, and so is a Buffer mkdtemp() prefix:

const fs = require('node:fs');
const path = require('node:path');
const vfs = require('node:vfs');

const myVfs = vfs.create();
myVfs.writeFileSync('/file.txt', 'x');
myVfs.symlinkSync('file.txt', '/link');
const link = path.join(myVfs.mount(), 'link');

fs.readlinkSync(link, 'buffer'); // 'file.txt' instead of a Buffer
fs.readlinkSync(link, 'hex');    // 'file.txt' instead of '66696c652e747874'

With RealFSProvider the options are passed on to the host fs, so readlink() with 'buffer' throws ERR_INVALID_ARG_TYPE and myVfs.realpathSync(p, 'hex') fails with EACCES.

The VirtualFileSystem readlink and realpath methods now get a string from the provider and apply the encoding with getOptions() and encodeRealpathResult(), as fs does. The helper moves from lib/fs.js to internal/fs/utils. The mkdtemp hooks do the same, which replaces the per-hook Buffer conversions for these methods in setup.js.

Since the VFS works with string paths, a RealFSProvider link 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 the fs realpath/readlink/mkdtemp tests pass on x64 Linux.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem. labels Sep 27, 2026
@codecov

codecov Bot commented Sep 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.57%. Comparing base (53f037e) to head (5b7bfe0).
⚠️ Report is 40 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66352      +/-   ##
==========================================
- Coverage   90.59%   90.57%   -0.02%     
==========================================
  Files         797      797              
  Lines      278475   278481       +6     
  Branches    53533    53535       +2     
==========================================
- Hits       252293   252247      -46     
- Misses      16532    16572      +40     
- Partials     9650     9662      +12     
Files with missing lines Coverage Δ
lib/fs.js 97.17% <100.00%> (-0.01%) ⬇️
lib/internal/fs/utils.js 96.32% <100.00%> (+0.03%) ⬆️
lib/internal/vfs/file_system.js 99.64% <100.00%> (+<0.01%) ⬆️
lib/internal/vfs/setup.js 87.59% <100.00%> (+0.13%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pipobscure
pipobscure reviewed Oct 16, 2026
View reviewed changes

@pipobscure pipobscure left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@christianaurichzm
vfs: fix readlink, realpath and mkdtemp encoding
5b7bfe0
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 <[email protected]>
@christianaurichzm
christianaurichzm force-pushed the vfs-path-encoding branch from 878c5f6 to 5b7bfe0 Compare October 22, 2026 14:31
@pipobscure

pipobscure commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@trivikr @mcollina this might be something you want have a look at.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@christianaurichzm

christianaurichzm commented Oct 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I rebased this on main and switched the test to --disable-warning=ExperimentalWarning, like the other VFS tests after #66318.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Oct 22, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 22, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 22, 2026
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
@nodejs-github-bot

nodejs-github-bot commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78641/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trivikr trivikr added author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. labels Oct 25, 2026
@nodejs-github-bot
nodejs-github-bot merged commit c7ae7ab into nodejs:main Oct 25, 2026
70 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Landed in c7ae7ab

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 25, 2026
@aduh95 aduh95 mentioned this pull request Oct 27, 2026
2026-10-28, Version 27.0.0-alpha.0.0.0 (Alpha) #67062
Merged
aduh95 pushed a commit that referenced this pull request Nov 12, 2026
@christianaurichzm @aduh95
vfs: fix readlink, realpath and mkdtemp encoding
4c5cc14
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 <[email protected]>
PR-URL: #66352
Reviewed-By: Matteo Collina <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
2026-11-30, Version 26.14.0 'Lithium' (LTS) #67664
Open
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@christianaurichzm @gabylb
vfs: fix readlink, realpath and mkdtemp encoding
f5bcb29
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 <[email protected]>
PR-URL: nodejs#66352
Reviewed-By: Matteo Collina <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pipobscure pipobscure pipobscure left review comments
@mcollina mcollina mcollina approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@christianaurichzm @pipobscure @nodejs-github-bot @mcollina @trivikr
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.