GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: fix glob TypeError on restricted dirs · nodejs/node@2990f17

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/fs
    • glob.js
  • test/parallel
    • test-fs-glob.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/fs/glob.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/glob.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class Cache {
143143
if (cached) {
144144
return cached;
145145
}
146-
const promise = PromisePrototypeThen(readdir(path, { __proto__: null, withFileTypes: true }), null, () => null);
146+
const promise = PromisePrototypeThen(readdir(path, { __proto__: null, withFileTypes: true }), null, () => []);
147147
this.#readdirCache.set(path, promise);
148148
return promise;
149149
}
Collapse file

‎test/parallel/test-fs-glob.mjs‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-glob.mjs
+22-1Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as common from '../common/index.mjs';
22
import tmpdir from '../common/tmpdir.js';
33
import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path';
44
import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises';
5-
import { glob, globSync, Dirent } from 'node:fs';
5+
import { glob, globSync, Dirent, chmodSync } from 'node:fs';
66
import { test, describe } from 'node:test';
77
import { pathToFileURL } from 'node:url';
88
import { promisify } from 'node:util';
@@ -518,3 +518,24 @@ describe('fsPromises glob - exclude', function() {
518518
});
519519
}
520520
});
521+
522+
describe('glob - with restricted directory', function() {
523+
test('*', async () => {
524+
const restrictedDir = tmpdir.resolve('restricted');
525+
await mkdir(restrictedDir, { recursive: true });
526+
chmodSync(restrictedDir, 0o000);
527+
try {
528+
const results = [];
529+
for await (const match of asyncGlob('*', { cwd: restrictedDir })) {
530+
results.push(match);
531+
}
532+
assert.ok(true, 'glob completed without throwing on readdir error');
533+
} finally {
534+
try {
535+
chmodSync(restrictedDir, 0o755);
536+
} catch {
537+
// ignore
538+
}
539+
}
540+
});
541+
});

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.