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 — fs: make mutating `options` in Promises `readdir()` not affect results · nodejs/node@92bcd52

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/fs
    • promises.js
  • test/parallel
    • test-fs-readdir-types.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/fs/promises.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,10 @@ async function readdirRecursive(originalPath, options) {
943943

944944
async function readdir(path, options) {
945945
options = getOptions(options);
946+
947+
// Make shallow copy to prevent mutating options from affecting results
948+
options = copyObject(options);
949+
946950
path = getValidatedPath(path);
947951
if (options.recursive) {
948952
return readdirRecursive(path, options);
Collapse file

‎test/parallel/test-fs-readdir-types.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-readdir-types.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ fs.readdir(readdirDir, {
7878
assertDirents(dirents);
7979
})().then(common.mustCall());
8080

81+
// Check that mutating options doesn't affect results
82+
(async () => {
83+
const options = { withFileTypes: true };
84+
const direntsPromise = fs.promises.readdir(readdirDir, options);
85+
options.withFileTypes = false;
86+
assertDirents(await direntsPromise);
87+
})().then(common.mustCall());
88+
8189
// Check for correct types when the binding returns unknowns
8290
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
8391
const oldReaddir = binding.readdir;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.