Skip to content

Commit 4cc0493

Browse files
LiviaMedeirosaduh95
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 8d485f1 commit 4cc0493

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
@@ -1530,6 +1530,9 @@ function readdir(path, options, callback) {
15301530
}
15311531

15321532
if (options.recursive) {
1533+
// Make shallow copy to prevent mutating options from affecting results
1534+
options = copyObject(options);
1535+
15331536
readdirRecursive(path, options, callback);
15341537
return;
15351538
}

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