Skip to content

Commit 773b904

Browse files
committed
fs: apply nocase to literal glob exclude patterns
On case-insensitive platforms include patterns match entries regardless of case, but literal (non-magic) exclude patterns were matched case-sensitively because exclude matchers are created with nocaseMagicOnly. Exclusion is a pure string match with no filesystem lookups, so disable nocaseMagicOnly for exclude matchers. Fixes: nodejs#58991 Refs: nodejs#63446 Signed-off-by: Yusuke Hayashi <[email protected]>
1 parent 460b202 commit 773b904

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎lib/internal/fs/glob.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,10 @@ class Glob {
664664
// consistent comparison before instantiating matchers.
665665
const matchers = exclude
666666
.map((pattern) => resolve(this.#root, pattern))
667-
.map((pattern) => createMatcher(pattern));
667+
// Exclude matching is a pure string comparison with no filesystem
668+
// lookups, so unlike include patterns, literal patterns must also
669+
// match case-insensitively on case-insensitive platforms.
670+
.map((pattern) => createMatcher(pattern, { nocaseMagicOnly: false }));
668671
this.#isExcluded = (value) =>
669672
matchers.some((matcher) => matcher.match(value));
670673
this.#results.setup(this.#root, this.#isExcluded);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,3 +998,31 @@ describe('glob - seen cache', function() {
998998
);
999999
});
10001000
});
1001+
1002+
// gh-58991: exclude patterns must apply the same case-sensitivity as include
1003+
// patterns. On case-insensitive filesystems include patterns match entries
1004+
// regardless of case, so literal exclude patterns must match that behavior.
1005+
const skipCaseTests = { skip: !common.isWindows && !common.isMacOS };
1006+
describe('glob - exclude case-insensitive consistency', skipCaseTests, function() {
1007+
test('literal exclude ignores case (sync)', () => {
1008+
assert.deepStrictEqual(
1009+
globSync('a/b', { cwd: fixtureDir, exclude: ['A/B'] }), []);
1010+
});
1011+
test('literal exclude matches differently-cased results (sync)', () => {
1012+
assert.deepStrictEqual(
1013+
globSync('A/b', { cwd: fixtureDir, exclude: ['a/b'] }), []);
1014+
});
1015+
test('literal exclude ignores case (async)', async () => {
1016+
const promisified = promisify(glob);
1017+
assert.deepStrictEqual(
1018+
await promisified('a/b', { cwd: fixtureDir, exclude: ['A/B'] }), []);
1019+
});
1020+
test('literal exclude ignores case (promise)', async () => {
1021+
const actual = [];
1022+
for await (const entry of asyncGlob(
1023+
'a/b', { cwd: fixtureDir, exclude: ['A/B'] })) {
1024+
actual.push(entry);
1025+
}
1026+
assert.deepStrictEqual(actual, []);
1027+
});
1028+
});

0 commit comments

Comments
 (0)