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 8d485f1

Browse filesBrowse files
LiviaMedeirosaduh95
authored andcommitted
fs: make mutating options in Promises 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 8288f57 commit 8d485f1
Copy full SHA for 8d485f1

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+12
-0
lines changed
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
@@ -944,6 +944,10 @@ async function readdirRecursive(originalPath, options) {
944944

945945
async function readdir(path, options) {
946946
options = getOptions(options);
947+
948+
// Make shallow copy to prevent mutating options from affecting results
949+
options = copyObject(options);
950+
947951
path = getValidatedPath(path);
948952
if (options.recursive) {
949953
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.