From f09ab6731ef71f24565025f8c207437a2f459807 Mon Sep 17 00:00:00 2001 From: Ziqi <19396458+ziqiq@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:17:22 -0400 Subject: [PATCH] fix: duplicated patterns in second phase preprocess loop PR-URL: https://github.com/isaacs/minimatch/pull/235 Credit: @ziqiq Close: #235 Reviewed-by: @isaacs --- src/index.ts | 8 +- .../test/optimization-level-2.ts.test.cjs | 144 ++++++++++++++++++ test/optimization-level-2.ts | 3 + 3 files changed, 152 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index d10e758..bb02378 100644 --- a/src/index.ts +++ b/src/index.ts @@ -675,9 +675,11 @@ export class Minimatch { globParts[j], !this.preserveMultipleSlashes ) - if (!matched) continue - globParts[i] = matched - globParts[j] = [] + if (matched) { + globParts[i] = [] + globParts[j] = matched + break + } } } return globParts.filter(gs => gs.length) diff --git a/tap-snapshots/test/optimization-level-2.ts.test.cjs b/tap-snapshots/test/optimization-level-2.ts.test.cjs index 5be720e..b30c009 100644 --- a/tap-snapshots/test/optimization-level-2.ts.test.cjs +++ b/tap-snapshots/test/optimization-level-2.ts.test.cjs @@ -4510,6 +4510,78 @@ Array [ ] ` +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {*,a,b} > defaults 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {*,a,b} > multislash 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {*,a,b} > no globstar 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {a,*,b} > defaults 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {a,*,b} > multislash 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {a,*,b} > no globstar 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {a,b,*} > defaults 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {a,b,*} > multislash 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {a,b,*} > no globstar 1`] = ` +Array [ + Array [ + "*", + ], +] +` + exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > linux > {a/**/b,a/b} > defaults 1`] = ` Array [ Array [ @@ -5838,6 +5910,78 @@ Array [ ] ` +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {*,a,b} > defaults 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {*,a,b} > multislash 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {*,a,b} > no globstar 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {a,*,b} > defaults 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {a,*,b} > multislash 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {a,*,b} > no globstar 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {a,b,*} > defaults 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {a,b,*} > multislash 1`] = ` +Array [ + Array [ + "*", + ], +] +` + +exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {a,b,*} > no globstar 1`] = ` +Array [ + Array [ + "*", + ], +] +` + exports[`test/optimization-level-2.ts > TAP > explicit pattern coalescing and optimization > win32 > {a/**/b,a/b} > defaults 1`] = ` Array [ Array [ diff --git a/test/optimization-level-2.ts b/test/optimization-level-2.ts index 2e5f989..a6db74d 100644 --- a/test/optimization-level-2.ts +++ b/test/optimization-level-2.ts @@ -60,6 +60,9 @@ t.test('explicit pattern coalescing and optimization', t => { './x/.././///.//./', '*/../**', '*/../**/?/*/[a-z]', + '{*,a,b}', + '{a,*,b}', + '{a,b,*}', ] const exp = (p: string) => braceExpand(p).map(s => s.split('/'))