mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
committed by
Node.js GitHub Bot
parent
743eacc48f
commit
b5e25aa2ce
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user