Skip to content

Commit

Permalink
Fix end-anchoring of negative extglobs
Browse files Browse the repository at this point in the history
Fix: #188
  • Loading branch information
isaacs committed Jan 14, 2023
1 parent baa3578 commit 49ae7a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion minimatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ class Minimatch {
}
nlAfter = cleanAfter

const dollar = nlAfter === '' && isSub !== SUBPARSE ? '$' : ''
const dollar = nlAfter === '' && isSub !== SUBPARSE ? '(?:$|\\/)' : ''

re = nlBefore + nlFirst + nlAfter + dollar + nlLast
}

Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test/basic.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports[`test/basic.js TAP basic tests > makeRe **/.x/** 2`] = `
`

exports[`test/basic.js TAP basic tests > makeRe *.!(js) 1`] = `
/^(?:(?!\\.)(?=.)[^/]*?\\.(?:(?!(?:js)$)[^/]*?))$/
/^(?:(?!\\.)(?=.)[^/]*?\\.(?:(?!(?:js)(?:$|\\/))[^/]*?))$/
`

exports[`test/basic.js TAP basic tests > makeRe *.\\* 1`] = `
Expand Down
9 changes: 9 additions & 0 deletions test/negative-extglob-anchoring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const t = require('tap')
const mm = require('../')
const pattern = 'a/b/*/!(bar)/*'
const nope = 'a/b/c/bar/x'
const yup = 'a/b/c/baz/x'
t.equal(mm(nope, pattern), false)
t.equal(mm.makeRe(pattern).test(nope), false)
t.equal(mm(yup, pattern), true)
t.equal(mm.makeRe(pattern).test(yup), true)

0 comments on commit 49ae7a2

Please sign in to comment.