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
7 changes: 4 additions & 3 deletions lib/internal/fs/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,15 +936,16 @@ function matchGlobPattern(path, pattern, windows = isWindows) {
validateString(path, 'path');
validateString(pattern, 'pattern');

const cacheKey = `${windows ? 'win32' : 'posix'}:${pattern}`;
let matcher;
if (patternFnCache.has(pattern)) {
matcher = patternFnCache.get(pattern);
if (patternFnCache.has(cacheKey)) {
matcher = patternFnCache.get(cacheKey);
} else {
matcher = createMatcher(pattern, {
kEmptyObject,
platform: windows ? 'win32' : 'posix',
});
patternFnCache.set(pattern, matcher);
patternFnCache.set(cacheKey, matcher);

if (patternFnCache.size >= kGlobPatternCacheLimit) {
patternFnCache.delete(patternFnCache.keys().next().value);
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-path-glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const globs = {
],
};

// Matchers for the same pattern must not be shared across path platforms.
assert.strictEqual(path.posix.matchesGlob('platform-cache/file', 'platform-cache/**'), true);
assert.strictEqual(path.win32.matchesGlob('platform-cache\\file', 'platform-cache/**'), true);

for (const [platform, platformGlobs] of Object.entries(globs)) {
for (const [pathStr, glob, expected] of platformGlobs) {
Expand Down
Loading