From 2f2b5ff1bb1b6a01f4404f7e475f0a2cba578ab7 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 15 Feb 2022 12:30:24 -0800 Subject: [PATCH] fix: trim pattern Overlooked that went missing at some point. Fix: https://github.com/isaacs/minimatch/issues/156 --- minimatch.js | 2 ++ test/basic.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) 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 }