Skip to content

Commit 7bcf27f

Browse files
author
Ethan Arrowood
committed
mend
1 parent 411ca77 commit 7bcf27f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/fs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,12 @@ function readdirSyncRecursive(basePath, options) {
14381438
handleErrorFromBinding(ctx);
14391439

14401440
if (withFileTypes) {
1441-
for (let i = 0; i < readdirResult[0].length; i++) {
1441+
// Calling `readdir` with `withFileTypes=true`, the result is an array of arrays.
1442+
// The first array is the names, and the second array is the types.
1443+
// They are guaranteed to be the same length; hence, setting `length` to the length
1444+
// of the first array within the result.
1445+
const length = readdirResult[0].length;
1446+
for (let i = 0; i < length; i++) {
14421447
const dirent = getDirent(path, readdirResult[0][i], readdirResult[1][i]);
14431448
ArrayPrototypePush(readdirResults, dirent);
14441449
if (dirent.isDirectory()) {

test/sequential/test-fs-readdir-recursive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function assertDirents(dirents) {
135135
dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1));
136136
for (const [i, dirent] of dirents.entries()) {
137137
assert(dirent instanceof fs.Dirent);
138+
assert.notStrictEqual(dirent.name, undefined);
138139
assert.strictEqual(getDirentPath(dirent), expected[i]);
139140
}
140141
}

0 commit comments

Comments
 (0)