Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/fs/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 22 additions & 1 deletion test/parallel/test-fs-glob.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
}
}
});
});
Loading