GeezerVison is showing github.com — fs: key glob matcher cache by platform · nodejs/node@b250b40
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/fs/glob.js +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -936,15 +936,16 @@ function matchGlobPattern(path, pattern, windows = isWindows) { |
936 | 936 | validateString(path, 'path'); |
937 | 937 | validateString(pattern, 'pattern'); |
938 | 938 |
|
| 939 | + const cacheKey = `${windows ? 'win32' : 'posix'}:${pattern}`; |
939 | 940 | let matcher; |
940 | | - if (patternFnCache.has(pattern)) { |
941 | | - matcher = patternFnCache.get(pattern); |
| 941 | + if (patternFnCache.has(cacheKey)) { |
| 942 | + matcher = patternFnCache.get(cacheKey); |
942 | 943 | } else { |
943 | 944 | matcher = createMatcher(pattern, { |
944 | 945 | kEmptyObject, |
945 | 946 | platform: windows ? 'win32' : 'posix', |
946 | 947 | }); |
947 | | - patternFnCache.set(pattern, matcher); |
| 948 | + patternFnCache.set(cacheKey, matcher); |
948 | 949 |
|
949 | 950 | if (patternFnCache.size >= kGlobPatternCacheLimit) { |
950 | 951 | patternFnCache.delete(patternFnCache.keys().next().value); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-path-glob.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,6 +31,9 @@ const globs = { |
31 | 31 | ], |
32 | 32 | }; |
33 | 33 |
|
| 34 | +// Matchers for the same pattern must not be shared across path platforms. |
| 35 | +assert.strictEqual(path.posix.matchesGlob('platform-cache/file', 'platform-cache/**'), true); |
| 36 | +assert.strictEqual(path.win32.matchesGlob('platform-cache\\file', 'platform-cache/**'), true); |
34 | 37 |
|
35 | 38 | for (const [platform, platformGlobs] of Object.entries(globs)) { |
36 | 39 | for (const [pathStr, glob, expected] of platformGlobs) { |
|