Skip to content

Commit 04d7c7a

Browse files
LiviaMedeirosruyadorno
authored andcommitted
fs: make mutating options in Callback readdir() not affect results
PR-URL: #56057 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 92bcd52 commit 04d7c7a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/fs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,9 @@ function readdir(path, options, callback) {
15331533
}
15341534

15351535
if (options.recursive) {
1536+
// Make shallow copy to prevent mutating options from affecting results
1537+
options = copyObject(options);
1538+
15361539
readdirRecursive(path, options, callback);
15371540
return;
15381541
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ fs.readdir(readdirDir, {
8686
assertDirents(await direntsPromise);
8787
})().then(common.mustCall());
8888

89+
{
90+
const options = { recursive: true, withFileTypes: true };
91+
fs.readdir(readdirDir, options, common.mustSucceed((dirents) => {
92+
assertDirents(dirents);
93+
}));
94+
options.withFileTypes = false;
95+
}
96+
8997
// Check for correct types when the binding returns unknowns
9098
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
9199
const oldReaddir = binding.readdir;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy