Skip to content

Commit

Permalink
fix: duplicated patterns in second phase preprocess loop
Browse files Browse the repository at this point in the history
PR-URL: #235
Credit: @ziqiq
Close: #235
Reviewed-by: @isaacs
  • Loading branch information
ziqiq authored and isaacs committed Jun 25, 2024
1 parent d5ef89f commit f09ab67
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
144 changes: 144 additions & 0 deletions tap-snapshots/test/optimization-level-2.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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 [
Expand Down
3 changes: 3 additions & 0 deletions test/optimization-level-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'))
Expand Down

0 comments on commit f09ab67

Please sign in to comment.