@@ -74,3 +74,46 @@ t.test('tail handling 2', async t => {
7474 pattern,
7575 } )
7676} )
77+
78+ // https://github.com/isaacs/minimatch/issues/329
79+ t . test ( 'body sections that differ in length' , async t => {
80+ const pattern = '**/a/b/c/**/d/**'
81+ for ( const level of [ 0 , 1 , 2 ] ) {
82+ const o = { optimizationLevel : level }
83+ t . equal ( minimatch ( 'a/b/c/d/e' , pattern , o ) , true )
84+ t . equal ( minimatch ( 'x/a/b/c/d/e' , pattern , o ) , true )
85+ t . equal ( minimatch ( 'a/b/c/x/d/e' , pattern , o ) , true )
86+ t . equal ( minimatch ( 'a/b/c/e' , pattern , o ) , false )
87+ t . equal ( minimatch ( 'a/b/c/d' , pattern , o ) , false )
88+ t . equal ( minimatch ( 'a/b/c/d/e' , '**/d/**/a/b/c/**' , o ) , false )
89+ t . equal ( minimatch ( 'd/x/a/b/c/e' , '**/d/**/a/b/c/**' , o ) , true )
90+ }
91+ } )
92+
93+ t . test ( 'the tail is not walked by the last **' , async t => {
94+ t . equal ( minimatch ( '.x/.x' , '**/.x/**/.x' ) , true )
95+ t . equal ( minimatch ( 'a/.x/b/.x' , '**/.x/**/.x' ) , true )
96+ t . equal ( minimatch ( 'a/.x/.y/.x' , '**/.x/**/.x' ) , false )
97+ } )
98+
99+ t . test ( 'partial does not try a place in the path twice' , async t => {
100+ const pattern =
101+ Array . from ( { length : 50 } , ( ) => '**/a' ) . join ( '/' ) + '/b/**'
102+ const path = Array ( 100 ) . fill ( 'a' ) . join ( '/' ) + '/b/c/d/.e/a/b'
103+ const alphabet = 'abcdefghijklmnopqrstuvwxyz' . repeat ( 5 )
104+ const p2 = '**/' + alphabet . split ( '' ) . join ( '/**/' ) + '/**'
105+ const f2 = alphabet
106+ . split ( '' )
107+ . flatMap ( c => alphabet . split ( '' ) . filter ( x => x !== c ) )
108+ . join ( '/' )
109+ for ( const [ f , p , dot , expect ] of [
110+ [ path , pattern , false , false ] ,
111+ [ path , pattern , true , true ] ,
112+ [ `${ f2 } /.x/y` , p2 , false , false ] ,
113+ ] as const ) {
114+ const start = performance . now ( )
115+ t . equal ( minimatch ( f , p , { partial : true , dot } ) , expect )
116+ const dur = performance . now ( ) - start
117+ t . ok ( dur < 1000 , 'should take less than 1s' , { found : dur } )
118+ }
119+ } )
0 commit comments