Skip to content

Commit

Permalink
fix: trim pattern
Browse files Browse the repository at this point in the history
Overlooked that went missing at some point.

Fix: #156
  • Loading branch information
isaacs committed Feb 15, 2022
1 parent 25d7c0d commit 2f2b5ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions minimatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ function Minimatch (pattern, options) {

if (!options) options = {}

pattern = pattern.trim()

// windows support: need to use /, not \
if (!options.allowWindowsEscape && path.sep !== '/') {
pattern = pattern.split(path.sep).join('/')
Expand Down
11 changes: 8 additions & 3 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ t.test('whitespace handling', t => {
t.equal(mm('x/y', 'y'), false)
t.equal(mm('x/y', 'y', { matchBase: true }), true)
t.equal(mm('x/ ', ' '), false)
t.equal(mm('x/ ', ' ', { matchBase: true }), true)
t.equal(mm('x/ ', ' ', { matchBase: true }), false)
t.equal(mm('x/', ''), false)
t.equal(mm('x/', '', { matchBase: true }), false)
t.equal(mm('', ''), true)
t.equal(mm(' ', ''), false)
t.equal(mm('', ' '), false)
t.equal(mm(' ', ' '), true)
t.equal(mm('', ' '), true)
t.equal(mm(' ', ' '), false)
t.end()
})

Expand Down Expand Up @@ -165,6 +165,11 @@ t.test('flipNegate', t => {
t.end()
})

t.test('pattern should be trimmed', t => {
t.equal(mm('x', ' x '), true)
t.end()
})

function alpha (a, b) {
return a > b ? 1 : -1
}

0 comments on commit 2f2b5ff

Please sign in to comment.