diff --git a/package-lock.json b/package-lock.json index 5f17388a..7f47e361 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "minimatch", - "version": "7.1.3", + "version": "7.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "minimatch", - "version": "7.1.3", + "version": "7.1.4", "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" diff --git a/package.json b/package.json index 95a16c45..ceca1d24 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Isaac Z. Schlueter (http://blog.izs.me)", "name": "minimatch", "description": "a glob matcher in javascript", - "version": "7.1.3", + "version": "7.1.4", "repository": { "type": "git", "url": "git://github.com/isaacs/minimatch.git" diff --git a/src/index.ts b/src/index.ts index 391769b0..5492d837 100644 --- a/src/index.ts +++ b/src/index.ts @@ -99,7 +99,10 @@ const defaultPlatform: Platform = ( : 'posix' ) as Platform type Sep = '\\' | '/' -const path:{[k:string]:{sep:Sep}} = { win32: { sep: '\\' }, posix: { sep: '/' } } +const path: { [k: string]: { sep: Sep } } = { + win32: { sep: '\\' }, + posix: { sep: '/' }, +} /* c8 ignore stop */ export const sep = defaultPlatform === 'win32' ? path.win32.sep : path.posix.sep @@ -538,7 +541,7 @@ export class Minimatch { // and ** cannot be reduced out by a .. pattern part like a regexp // or most strings (other than .., ., and '') can be. // - //
/**/../

/ -> {

/../

/,

/**/

/} + //

/**/../

/

/ -> {

/../

/

/,

/**/

/

/} //

// -> 
/
   // 
/

/../ ->

/
   // **/**/ -> **/
@@ -549,7 +552,7 @@ export class Minimatch {
     let didSomething = false
     do {
       didSomething = false
-      // 
/**/../

/ -> {

/../

/,

/**/

/} + //

/**/../

/

/ -> {

/../

/

/,

/**/

/

/} for (let parts of globParts) { let gs: number = -1 while (-1 !== (gs = parts.indexOf('**', gs + 1))) { @@ -566,8 +569,18 @@ export class Minimatch { let next = parts[gs + 1] const p = parts[gs + 2] + const p2 = parts[gs + 3] if (next !== '..') continue - if (!p || p === '.' || p === '..') continue + if ( + !p || + p === '.' || + p === '..' || + !p2 || + p2 === '.' || + p2 === '..' + ) { + continue + } didSomething = true // edit parts in place, and push the new one parts.splice(gs, 1) diff --git a/tap-snapshots/test/optimization-level-2.ts.test.cjs b/tap-snapshots/test/optimization-level-2.ts.test.cjs index 5daea2b8..798fac79 100644 --- a/tap-snapshots/test/optimization-level-2.ts.test.cjs +++ b/tap-snapshots/test/optimization-level-2.ts.test.cjs @@ -743,53 +743,80 @@ Array [ ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > defaults 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../*/x > defaults 1`] = ` Array [ Array [ "..", + "*", "x", ], Array [ "**", + "*", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > defaults 2`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../*/x > multislash 1`] = ` Array [ Array [ "..", + "*", "x", ], Array [ "**", + "*", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > multislash 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../*/x > no globstar 1`] = ` +Array [ + Array [ + "*", + "x", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > defaults 1`] = ` Array [ Array [ + "**", "..", "x", ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > defaults 2`] = ` +Array [ Array [ "**", + "..", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > multislash 2`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > multislash 1`] = ` Array [ Array [ + "**", "..", "x", ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x > multislash 2`] = ` +Array [ Array [ "**", + "..", "x", ], ] @@ -811,6 +838,128 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/* > defaults 1`] = ` +Array [ + Array [ + "..", + "x", + "*", + ], + Array [ + "**", + "x", + "*", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/* > multislash 1`] = ` +Array [ + Array [ + "..", + "x", + "*", + ], + Array [ + "**", + "x", + "*", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/* > no globstar 1`] = ` +Array [ + Array [ + "x", + "*", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/y > defaults 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + ], + Array [ + "**", + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/y > multislash 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + ], + Array [ + "**", + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/y > no globstar 1`] = ` +Array [ + Array [ + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/y/z > defaults 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + "z", + ], + Array [ + "**", + "x", + "y", + "z", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/y/z > multislash 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + "z", + ], + Array [ + "**", + "x", + "y", + "z", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux **/../x/y/z > no globstar 1`] = ` +Array [ + Array [ + "x", + "y", + "z", + ], +] +` + exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux */../** > defaults 1`] = ` Array [ Array [ @@ -837,6 +986,41 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux */../**/?/*/[a-z] > defaults 1`] = ` +Array [ + Array [ + ".", + "**", + "?", + "*", + "[a-z]", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux */../**/?/*/[a-z] > multislash 1`] = ` +Array [ + Array [ + ".", + "**", + "?", + "*", + "[a-z]", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux */../**/?/*/[a-z] > no globstar 1`] = ` +Array [ + Array [ + "*", + "?", + "*", + "[a-z]", + ], +] +` + exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./ > defaults 1`] = ` Array [ Array [ @@ -923,37 +1107,73 @@ exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimi Array [ Array [ ".", + "**", "..", "x", ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./**/../x > multislash 1`] = ` +Array [ Array [ ".", "**", + "..", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./**/../x > multislash 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./**/../x > no globstar 1`] = ` +Array [ + Array [ + ".", + "x", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./**/../x/y > defaults 1`] = ` Array [ Array [ ".", "..", "x", + "y", ], Array [ ".", "**", "x", + "y", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./**/../x > no globstar 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./**/../x/y > multislash 1`] = ` +Array [ + Array [ + ".", + "..", + "x", + "y", + ], + Array [ + ".", + "**", + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization linux ./**/../x/y > no globstar 1`] = ` Array [ Array [ ".", "x", + "y", ], ] ` @@ -1851,53 +2071,80 @@ Array [ ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > defaults 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../*/x > defaults 1`] = ` Array [ Array [ "..", + "*", "x", ], Array [ "**", + "*", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > defaults 2`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../*/x > multislash 1`] = ` Array [ Array [ "..", + "*", "x", ], Array [ "**", + "*", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > multislash 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../*/x > no globstar 1`] = ` +Array [ + Array [ + "*", + "x", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > defaults 1`] = ` Array [ Array [ + "**", "..", "x", ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > defaults 2`] = ` +Array [ Array [ "**", + "..", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > multislash 2`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > multislash 1`] = ` Array [ Array [ + "**", "..", "x", ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x > multislash 2`] = ` +Array [ Array [ "**", + "..", "x", ], ] @@ -1919,6 +2166,128 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/* > defaults 1`] = ` +Array [ + Array [ + "..", + "x", + "*", + ], + Array [ + "**", + "x", + "*", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/* > multislash 1`] = ` +Array [ + Array [ + "..", + "x", + "*", + ], + Array [ + "**", + "x", + "*", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/* > no globstar 1`] = ` +Array [ + Array [ + "x", + "*", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/y > defaults 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + ], + Array [ + "**", + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/y > multislash 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + ], + Array [ + "**", + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/y > no globstar 1`] = ` +Array [ + Array [ + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/y/z > defaults 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + "z", + ], + Array [ + "**", + "x", + "y", + "z", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/y/z > multislash 1`] = ` +Array [ + Array [ + "..", + "x", + "y", + "z", + ], + Array [ + "**", + "x", + "y", + "z", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 **/../x/y/z > no globstar 1`] = ` +Array [ + Array [ + "x", + "y", + "z", + ], +] +` + exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 */../** > defaults 1`] = ` Array [ Array [ @@ -1945,6 +2314,41 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 */../**/?/*/[a-z] > defaults 1`] = ` +Array [ + Array [ + ".", + "**", + "?", + "*", + "[a-z]", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 */../**/?/*/[a-z] > multislash 1`] = ` +Array [ + Array [ + ".", + "**", + "?", + "*", + "[a-z]", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 */../**/?/*/[a-z] > no globstar 1`] = ` +Array [ + Array [ + "*", + "?", + "*", + "[a-z]", + ], +] +` + exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./ > defaults 1`] = ` Array [ Array [ @@ -2031,37 +2435,73 @@ exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimi Array [ Array [ ".", + "**", "..", "x", ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./**/../x > multislash 1`] = ` +Array [ Array [ ".", "**", + "..", "x", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./**/../x > multislash 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./**/../x > no globstar 1`] = ` +Array [ + Array [ + ".", + "x", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./**/../x/y > defaults 1`] = ` Array [ Array [ ".", "..", "x", + "y", ], Array [ ".", "**", "x", + "y", ], ] ` -exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./**/../x > no globstar 1`] = ` +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./**/../x/y > multislash 1`] = ` +Array [ + Array [ + ".", + "..", + "x", + "y", + ], + Array [ + ".", + "**", + "x", + "y", + ], +] +` + +exports[`test/optimization-level-2.ts TAP explicit pattern coalescing and optimization win32 ./**/../x/y > no globstar 1`] = ` Array [ Array [ ".", "x", + "y", ], ] ` diff --git a/test/optimization-level-2.ts b/test/optimization-level-2.ts index 26d7d258..090c88e9 100644 --- a/test/optimization-level-2.ts +++ b/test/optimization-level-2.ts @@ -26,16 +26,21 @@ t.test('explicit pattern coalescing and optimization', t => { const patterns = [ '**', '**/../x', + '**/../*/x', + '**/../x/*', './**', './**/', './**/x', './**/../x', + './**/../x/y', '//host/share', '//host/share/', '//host/share//s/o//me////.//path', '**/..', '**/../', '**/../x', + '**/../x/y', + '**/../x/y/z', 'a/b/c/**///../x/y/z', 'a/b/c/..///d', 'a/{*,c}/b', @@ -54,6 +59,7 @@ t.test('explicit pattern coalescing and optimization', t => { './', './x/.././///.//./', '*/../**', + '*/../**/?/*/[a-z]', ] const exp = (p: string) => braceExpand(p).map(s => s.split('/'))