Skip to content
Open
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
6 changes: 4 additions & 2 deletions lib/internal/fs/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ async function getDirent(path) {
* @returns {DirentFromStats|null}
*/
function getDirentSync(path) {
const stat = lstatSync(path, { throwIfNoEntry: false });
if (stat === undefined) {
let stat;
try {
stat = lstatSync(path);
} catch {
return null;
}
return new DirentFromStats(basename(path), stat, dirname(path));
Expand Down
20 changes: 19 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, chmodSync } from 'node:fs';
import { glob, globSync, Dirent, chmodSync, writeFileSync, rmSync } from 'node:fs';
import { test, describe } from 'node:test';
import { pathToFileURL } from 'node:url';
import { promisify } from 'node:util';
Expand Down Expand Up @@ -543,3 +543,21 @@ describe('glob - with restricted directory', function() {
}
});
});

describe('globSync - ENOTDIR', function() {
test('should return empty array when a file is treated as a directory', () => {
const file = tmpdir.resolve('foo');
writeFileSync(file, '');
try {
const pattern = 'foo{,/bar}';
const actual = globSync(pattern, { cwd: tmpdir.path }).sort();
assert.deepStrictEqual(actual, ['foo']);
} finally {
try {
rmSync(file);
} catch {
// ignore
}
}
});
});
Loading