@ -148,6 +148,12 @@ function Minimatch (pattern, options) {
if ( ! options ) options = { }
pattern = pattern . trim ( )
// windows: need to use /, not \
// On other platforms, \ is a valid (albeit bad) filename char.
if ( platform === "win32" ) {
pattern = pattern . split ( "\\" ) . join ( "/" )
}
// lru storage.
// these things aren't particularly big, but walking down the string
// and turning it into a regexp can get pretty costly.
@ -911,6 +917,9 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
if ( p === false ) return false
if ( p === GLOBSTAR ) {
if ( options . debug )
console . error ( 'GLOBSTAR' , [ pattern , p , f ] )
// "**"
// a/**/b/**/c would match the following:
// a/b/x/y/z/c
@ -922,7 +931,8 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
// If so, return success.
// If not, the ** "swallows" a segment, and try again.
// This is recursively awful.
// a/b/x/y/z/c
//
// a/**/b/**/c matching a/b/x/y/z/c
// - a matches a
// - doublestar
// - matchOne(b/x/y/z/c, b/**/c)
@ -935,6 +945,8 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
var fr = fi
, pr = pi + 1
if ( pr === pl ) {
if ( options . debug )
console . error ( '** at the end' )
// a ** at the end will just swallow the rest.
// We have found a match.
// however, it will not swallow /.x, unless
@ -951,18 +963,31 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
// ok, let's see if we can swallow whatever we can.
WHILE : while ( fr < fl ) {
var swallowee = file [ fr ]
if ( swallowee === "." || swallowee === ".." ||
( ! options . dot && swallowee . charAt ( 0 ) === "." ) ) {
// console.error("dot detected!")
break WHILE
if ( options . debug ) {
console . error ( '\nglobstar while' ,
file , fr , pattern , pr , swallowee )
}
// XXX remove this slice. Just pass the start index.
if ( this . matchOne ( file . slice ( fr ) , pattern . slice ( pr ) , partial ) ) {
if ( options . debug )
console . error ( 'globstar found match!' , fr , fl , swallowee )
// found a match.
return true
} else {
// can't swallow "." or ".." ever.
// can only swallow ".foo" when explicitly asked.
if ( swallowee === "." || swallowee === ".." ||
( ! options . dot && swallowee . charAt ( 0 ) === "." ) ) {
if ( options . debug )
console . error ( "dot detected!" , file , fr , pattern , pr )
break WHILE
}
// ** swallows a segment, and continue.
if ( options . debug )
console . error ( 'globstar swallow a segment, and continue' )
fr ++
}
}