Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4cc0493

Browse filesBrowse 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
Copy full SHA for 4cc0493

File tree

Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+3Lines 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
}
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
@@ -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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.