diff --git a/minimatch.js b/minimatch.js index b0e2e814..fda45ade 100644 --- a/minimatch.js +++ b/minimatch.js @@ -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('/') diff --git a/test/basic.js b/test/basic.js index 5efa68f0..66608180 100644 --- a/test/basic.js +++ b/test/basic.js @@ -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() }) @@ -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 }