fs: make mutating options in Promises readdir() not affect results

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
LiviaMedeiros authored and Node.js GitHub Bot committed 2024-12-12 21:25:52 +00:00
1 parent 743eacc48f
commit b5e25aa2ce
2 files changed
+12

No files matched your search

+4
View File
@@ -944,6 +944,10 @@ async function readdirRecursive(originalPath, options) {
async function readdir(path, options) {
options = getOptions(options);
// Make shallow copy to prevent mutating options from affecting results
options = copyObject(options);
path = getValidatedPath(path);
if (options.recursive) {
return readdirRecursive(path, options);
+8
View File
@@ -78,6 +78,14 @@ fs.readdir(readdirDir, {
assertDirents(dirents);
})().then(common.mustCall());
// Check that mutating options doesn't affect results
(async () => {
const options = { withFileTypes: true };
const direntsPromise = fs.promises.readdir(readdirDir, options);
options.withFileTypes = false;
assertDirents(await direntsPromise);
})().then(common.mustCall());
// Check for correct types when the binding returns unknowns
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
const oldReaddir = binding.readdir;