From b73bd6aab3ff8278e4aaad3814f940a6863c5bea Mon Sep 17 00:00:00 2001 From: adsolutions Date: Sat, 5 Dec 2015 20:33:08 +0100 Subject: [PATCH 1/2] fix issue when a negative pattern consists of a group match, the wrong pattern was fed to minimatch --- lib/globule.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/globule.js b/lib/globule.js index 5a3eeac..a4f8149 100644 --- a/lib/globule.js +++ b/lib/globule.js @@ -1,4 +1,4 @@ -/* +/*test * globule * https://github.com/cowboy/node-globule * @@ -31,7 +31,12 @@ function processPatterns(patterns, options, fn) { } // The first character is ! (exclusion). Remove any filepaths from the // result set that match this pattern, sans leading !. - var filterFn = minimatch.filter(pattern.slice(1), options); + var patt = pattern.slice(1); + if(patt.indexOf('(') === 0){//if next character in the glob is a ( assume grouping pattern, and make a positive match all in group by prefixing with a * + patt = '*'+patt; + } + var filterFn = minimatch.filter(patt, options); + result = _.filter(result, function(filepath) { return !filterFn(filepath); }); From e16a1d8c56d125925d7aa1ee47649555b7adcc15 Mon Sep 17 00:00:00 2001 From: adsolutions Date: Sat, 5 Dec 2015 20:55:35 +0100 Subject: [PATCH 2/2] - added unit test - removed wrong comment --- lib/globule.js | 10 +++++----- test/globule_test.js | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/globule.js b/lib/globule.js index a4f8149..5044a75 100644 --- a/lib/globule.js +++ b/lib/globule.js @@ -1,4 +1,4 @@ -/*test +/* * globule * https://github.com/cowboy/node-globule * @@ -31,10 +31,10 @@ function processPatterns(patterns, options, fn) { } // The first character is ! (exclusion). Remove any filepaths from the // result set that match this pattern, sans leading !. - var patt = pattern.slice(1); - if(patt.indexOf('(') === 0){//if next character in the glob is a ( assume grouping pattern, and make a positive match all in group by prefixing with a * - patt = '*'+patt; - } + var patt = pattern.slice(1); + if(patt.indexOf('(') === 0){//if next character in the glob is a ( assume grouping pattern, and make a positive match all in group by prefixing with a * + patt = '*'+patt; + } var filterFn = minimatch.filter(patt, options); result = _.filter(result, function(filepath) { diff --git a/test/globule_test.js b/test/globule_test.js index 4b921ea..8e1a5a7 100644 --- a/test/globule_test.js +++ b/test/globule_test.js @@ -66,9 +66,10 @@ exports['match'] = { test.done(); }, 'exclusion': function(test) { - test.expect(5); + test.expect(6); test.deepEqual(globule.match(['!*.js'], ['foo.js', 'bar.js']), [], 'solitary exclusion should match nothing'); test.deepEqual(globule.match(['*.js', '!*.js'], ['foo.js', 'bar.js']), [], 'exclusion should cancel match'); + test.deepEqual(globule.match(['*.js', '!(foo|bar).js'], ['foo.js', 'bar.js', 'baz.js']), ['baz.js'], 'group exlusion should be handled correctly'); test.deepEqual(globule.match(['*.js', '!f*.js'], ['foo.js', 'bar.js', 'baz.js']), ['bar.js', 'baz.js'], 'partial exclusion should partially cancel match'); @@ -188,7 +189,7 @@ exports['find'] = { 'exclusion': function(test) { test.expect(8); test.deepEqual(globule.find(['!js/*.js']), [], 'solitary exclusion should match nothing'); - test.deepEqual(globule.find(['js/bar.js','!js/bar.js']), [], 'exclusion should negate match'); + test.deepEqual(globule.find(['js/bar.js','!js/bar.js']), [], 'exclusion should negate match'); test.deepEqual(globule.find(['**/*.js', '!js/foo.js']), ['js/bar.js'], 'should omit single file from matched set');