diff --git a/lib/internal/fs/glob.js b/lib/internal/fs/glob.js index 14180f936ac..05252348dae 100644 --- a/lib/internal/fs/glob.js +++ b/lib/internal/fs/glob.js @@ -143,7 +143,7 @@ class Cache { if (cached) { return cached; } - const promise = PromisePrototypeThen(readdir(path, { __proto__: null, withFileTypes: true }), null, () => null); + const promise = PromisePrototypeThen(readdir(path, { __proto__: null, withFileTypes: true }), null, () => []); this.#readdirCache.set(path, promise); return promise; } diff --git a/test/parallel/test-fs-glob.mjs b/test/parallel/test-fs-glob.mjs index b3708f46637..490ea247823 100644 --- a/test/parallel/test-fs-glob.mjs +++ b/test/parallel/test-fs-glob.mjs @@ -2,7 +2,7 @@ import * as common from '../common/index.mjs'; import tmpdir from '../common/tmpdir.js'; import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path'; import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises'; -import { glob, globSync, Dirent } from 'node:fs'; +import { glob, globSync, Dirent, chmodSync } from 'node:fs'; import { test, describe } from 'node:test'; import { pathToFileURL } from 'node:url'; import { promisify } from 'node:util'; @@ -518,3 +518,24 @@ describe('fsPromises glob - exclude', function() { }); } }); + +describe('glob - with restricted directory', function() { + test('*', async () => { + const restrictedDir = tmpdir.resolve('restricted'); + await mkdir(restrictedDir, { recursive: true }); + chmodSync(restrictedDir, 0o000); + try { + const results = []; + for await (const match of asyncGlob('*', { cwd: restrictedDir })) { + results.push(match); + } + assert.ok(true, 'glob completed without throwing on readdir error'); + } finally { + try { + chmodSync(restrictedDir, 0o755); + } catch { + // ignore + } + } + }); +});