Permalink
Browse files

Fixing handling of the minimatch matchBase option.

  • Loading branch information...
1 parent 5bede52 commit 906180d4172a10b613894e83648634db86640a8f @cowboy committed Apr 10, 2012
Showing with 14 additions and 1 deletion.
  1. +6 −1 lib/glob.js
  2. +8 −0 test/glob_test.js
View
@@ -44,7 +44,12 @@ exports.glob = function(pattern, options) {
// Don't recurse if we don't have to. Limit max depth.
var maxDepth = betterPattern.indexOf('**') >= 0 ? (options.maxDepth || 99)
: betterPattern.split('/').length;
-
+ // If minimatch 'matchBase' option is true, and the pattern doesn't contain
+ // ** or /, use the pattern as-specified and recurse to max.
+ if (options.matchBase && !/\*\*|\//.test(pattern)) {
+ maxDepth = options.maxDepth || 99;
+ absPattern = pattern;
+ }
// Iterate over all sub-files and directories in a brute-force and not-at-all
// efficient way.
var filepaths = [];
View
@@ -74,5 +74,13 @@ exports['globsync'] = {
test.deepEqual(globsync.glob('../test/fixture/**/?oo'), fileList([1], prefix), '../test/fixture/**/?oo should match');
process.chdir('..');
test.done();
+ },
+ 'options.matchBase': function(test) {
+ test.expect(3);
+ var prefix = path.resolve(process.cwd());
+ test.deepEqual(globsync.glob('boot', {matchBase: true}), fileList([0, 4, 5, 6], ''), 'should match.');
+ test.deepEqual(globsync.glob('**/boot', {matchBase: true}), fileList([0, 4, 5, 6], ''), 'should match.');
+ test.deepEqual(globsync.glob('**/b*/boot', {matchBase: true}), fileList([4, 5], ''), 'should match.');
+ test.done();
}
};

0 comments on commit 906180d

Please sign in to comment.