Skip to content
This repository
Browse code

minimatch@0.2.8

  • Loading branch information...
commit 5fd8258786e0c5382d375e4840d1d65293a92e64 1 parent e043d6a
Isaac Z. Schlueter authored October 25, 2012
35  node_modules/minimatch/minimatch.js
@@ -148,6 +148,12 @@ function Minimatch (pattern, options) {
148 148
   if (!options) options = {}
149 149
   pattern = pattern.trim()
150 150
 
  151
+  // windows: need to use /, not \
  152
+  // On other platforms, \ is a valid (albeit bad) filename char.
  153
+  if (platform === "win32") {
  154
+    pattern = pattern.split("\\").join("/")
  155
+  }
  156
+
151 157
   // lru storage.
152 158
   // these things aren't particularly big, but walking down the string
153 159
   // and turning it into a regexp can get pretty costly.
@@ -911,6 +917,9 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
911 917
     if (p === false) return false
912 918
 
913 919
     if (p === GLOBSTAR) {
  920
+      if (options.debug)
  921
+        console.error('GLOBSTAR', [pattern, p, f])
  922
+
914 923
       // "**"
915 924
       // a/**/b/**/c would match the following:
916 925
       // a/b/x/y/z/c
@@ -922,7 +931,8 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
922 931
       // If so, return success.
923 932
       // If not, the ** "swallows" a segment, and try again.
924 933
       // This is recursively awful.
925  
-      // a/b/x/y/z/c
  934
+      //
  935
+      // a/**/b/**/c matching a/b/x/y/z/c
926 936
       // - a matches a
927 937
       // - doublestar
928 938
       //   - matchOne(b/x/y/z/c, b/**/c)
@@ -935,6 +945,8 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
935 945
       var fr = fi
936 946
         , pr = pi + 1
937 947
       if (pr === pl) {
  948
+        if (options.debug)
  949
+          console.error('** at the end')
938 950
         // a ** at the end will just swallow the rest.
939 951
         // We have found a match.
940 952
         // however, it will not swallow /.x, unless
@@ -951,18 +963,31 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
951 963
       // ok, let's see if we can swallow whatever we can.
952 964
       WHILE: while (fr < fl) {
953 965
         var swallowee = file[fr]
954  
-        if (swallowee === "." || swallowee === ".." ||
955  
-            (!options.dot && swallowee.charAt(0) === ".")) {
956  
-          // console.error("dot detected!")
957  
-          break WHILE
  966
+
  967
+        if (options.debug) {
  968
+          console.error('\nglobstar while',
  969
+                        file, fr, pattern, pr, swallowee)
958 970
         }
959 971
 
960 972
         // XXX remove this slice.  Just pass the start index.
961 973
         if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  974
+          if (options.debug)
  975
+            console.error('globstar found match!', fr, fl, swallowee)
962 976
           // found a match.
963 977
           return true
964 978
         } else {
  979
+          // can't swallow "." or ".." ever.
  980
+          // can only swallow ".foo" when explicitly asked.
  981
+          if (swallowee === "." || swallowee === ".." ||
  982
+              (!options.dot && swallowee.charAt(0) === ".")) {
  983
+            if (options.debug)
  984
+              console.error("dot detected!", file, fr, pattern, pr)
  985
+            break WHILE
  986
+          }
  987
+
965 988
           // ** swallows a segment, and continue.
  989
+          if (options.debug)
  990
+            console.error('globstar swallow a segment, and continue')
966 991
           fr ++
967 992
         }
968 993
       }
7  node_modules/minimatch/package.json
@@ -6,7 +6,7 @@
6 6
   },
7 7
   "name": "minimatch",
8 8
   "description": "a glob matcher in javascript",
9  
-  "version": "0.2.6",
  9
+  "version": "0.2.8",
10 10
   "repository": {
11 11
     "type": "git",
12 12
     "url": "git://github.com/isaacs/minimatch.git"
@@ -29,6 +29,7 @@
29 29
     "url": "http://github.com/isaacs/minimatch/raw/master/LICENSE"
30 30
   },
31 31
   "readme": "# minimatch\n\nA minimal matching utility.\n\n[![Build Status](https://secure.travis-ci.org/isaacs/minimatch.png)](http://travis-ci.org/isaacs/minimatch)\n\n\nThis is the matching library used internally by npm.\n\nEventually, it will replace the C binding in node-glob.\n\nIt works by converting glob expressions into JavaScript `RegExp`\nobjects.\n\n## Usage\n\n```javascript\nvar minimatch = require(\"minimatch\")\n\nminimatch(\"bar.foo\", \"*.foo\") // true!\nminimatch(\"bar.foo\", \"*.bar\") // false!\n```\n\n## Features\n\nSupports these glob features:\n\n* Brace Expansion\n* Extended glob matching\n* \"Globstar\" `**` matching\n\nSee:\n\n* `man sh`\n* `man bash`\n* `man 3 fnmatch`\n* `man 5 gitignore`\n\n### Comparisons to other fnmatch/glob implementations\n\nWhile strict compliance with the existing standards is a worthwhile\ngoal, some discrepancies exist between minimatch and other\nimplementations, and are intentional.\n\nIf the pattern starts with a `!` character, then it is negated.  Set the\n`nonegate` flag to suppress this behavior, and treat leading `!`\ncharacters normally.  This is perhaps relevant if you wish to start the\npattern with a negative extglob pattern like `!(a|B)`.  Multiple `!`\ncharacters at the start of a pattern will negate the pattern multiple\ntimes.\n\nIf a pattern starts with `#`, then it is treated as a comment, and\nwill not match anything.  Use `\\#` to match a literal `#` at the\nstart of a line, or set the `nocomment` flag to suppress this behavior.\n\nThe double-star character `**` is supported by default, unless the\n`noglobstar` flag is set.  This is supported in the manner of bsdglob\nand bash 4.1, where `**` only has special significance if it is the only\nthing in a path part.  That is, `a/**/b` will match `a/x/y/b`, but\n`a/**b` will not.  **Note that this is different from the way that `**` is\nhandled by ruby's `Dir` class.**\n\nIf an escaped pattern has no matches, and the `nonull` flag is set,\nthen minimatch.match returns the pattern as-provided, rather than\ninterpreting the character escapes.  For example,\n`minimatch.match([], \"\\\\*a\\\\?\")` will return `\"\\\\*a\\\\?\"` rather than\n`\"*a?\"`.  This is akin to setting the `nullglob` option in bash, except\nthat it does not resolve escaped pattern characters.\n\nIf brace expansion is not disabled, then it is performed before any\nother interpretation of the glob pattern.  Thus, a pattern like\n`+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded\n**first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are\nchecked for validity.  Since those two are valid, matching proceeds.\n\n\n## Minimatch Class\n\nCreate a minimatch object by instanting the `minimatch.Minimatch` class.\n\n```javascript\nvar Minimatch = require(\"minimatch\").Minimatch\nvar mm = new Minimatch(pattern, options)\n```\n\n### Properties\n\n* `pattern` The original pattern the minimatch object represents.\n* `options` The options supplied to the constructor.\n* `set` A 2-dimensional array of regexp or string expressions.\n  Each row in the\n  array corresponds to a brace-expanded pattern.  Each item in the row\n  corresponds to a single path-part.  For example, the pattern\n  `{a,b/c}/d` would expand to a set of patterns like:\n\n        [ [ a, d ]\n        , [ b, c, d ] ]\n\n    If a portion of the pattern doesn't have any \"magic\" in it\n    (that is, it's something like `\"foo\"` rather than `fo*o?`), then it\n    will be left as a string rather than converted to a regular\n    expression.\n\n* `regexp` Created by the `makeRe` method.  A single regular expression\n  expressing the entire pattern.  This is useful in cases where you wish\n  to use the pattern somewhat like `fnmatch(3)` with `FNM_PATH` enabled.\n* `negate` True if the pattern is negated.\n* `comment` True if the pattern is a comment.\n* `empty` True if the pattern is `\"\"`.\n\n### Methods\n\n* `makeRe` Generate the `regexp` member if necessary, and return it.\n  Will return `false` if the pattern is invalid.\n* `match(fname)` Return true if the filename matches the pattern, or\n  false otherwise.\n* `matchOne(fileArray, patternArray, partial)` Take a `/`-split\n  filename, and match it against a single row in the `regExpSet`.  This\n  method is mainly for internal use, but is exposed so that it can be\n  used by a glob-walker that needs to avoid excessive filesystem calls.\n\nAll other methods are internal, and will be called as necessary.\n\n## Functions\n\nThe top-level exported function has a `cache` property, which is an LRU\ncache set to store 100 items.  So, calling these methods repeatedly\nwith the same pattern and options will use the same Minimatch object,\nsaving the cost of parsing it multiple times.\n\n### minimatch(path, pattern, options)\n\nMain export.  Tests a path against the pattern using the options.\n\n```javascript\nvar isJS = minimatch(file, \"*.js\", { matchBase: true })\n```\n\n### minimatch.filter(pattern, options)\n\nReturns a function that tests its\nsupplied argument, suitable for use with `Array.filter`.  Example:\n\n```javascript\nvar javascripts = fileList.filter(minimatch.filter(\"*.js\", {matchBase: true}))\n```\n\n### minimatch.match(list, pattern, options)\n\nMatch against the list of\nfiles, in the style of fnmatch or glob.  If nothing is matched, and\noptions.nonull is set, then return a list containing the pattern itself.\n\n```javascript\nvar javascripts = minimatch.match(fileList, \"*.js\", {matchBase: true}))\n```\n\n### minimatch.makeRe(pattern, options)\n\nMake a regular expression object from the pattern.\n\n## Options\n\nAll options are `false` by default.\n\n### debug\n\nDump a ton of stuff to stderr.\n\n### nobrace\n\nDo not expand `{a,b}` and `{1..3}` brace sets.\n\n### noglobstar\n\nDisable `**` matching against multiple folder names.\n\n### dot\n\nAllow patterns to match filenames starting with a period, even if\nthe pattern does not explicitly have a period in that spot.\n\nNote that by default, `a/**/b` will **not** match `a/.d/b`, unless `dot`\nis set.\n\n### noext\n\nDisable \"extglob\" style patterns like `+(a|b)`.\n\n### nocase\n\nPerform a case-insensitive match.\n\n### nonull\n\nWhen a match is not found by `minimatch.match`, return a list containing\nthe pattern itself.  When set, an empty list is returned if there are\nno matches.\n\n### matchBase\n\nIf set, then patterns without slashes will be matched\nagainst the basename of the path if it contains slashes.  For example,\n`a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.\n\n### nocomment\n\nSuppress the behavior of treating `#` at the start of a pattern as a\ncomment.\n\n### nonegate\n\nSuppress the behavior of treating a leading `!` character as negation.\n\n### flipNegate\n\nReturns from negate expressions the same as if they were not negated.\n(Ie, true on a hit, false on a miss.)\n",
32  
-  "_id": "minimatch@0.2.6",
33  
-  "_from": "minimatch@~0.2"
  32
+  "readmeFilename": "README.md",
  33
+  "_id": "minimatch@0.2.8",
  34
+  "_from": "minimatch@~0.2.8"
34 35
 }
24  node_modules/minimatch/test/basic.js
@@ -231,6 +231,30 @@ tap.test("basic tests", function (t) {
231 231
       }
232 232
     , ["*.!(js)", ["foo.bar", "foo.", "boo.js.boo"] ]
233 233
 
  234
+    // https://github.com/isaacs/minimatch/issues/5
  235
+    , function () {
  236
+        files = [ 'a/b/.x/c'
  237
+                , 'a/b/.x/c/d'
  238
+                , 'a/b/.x/c/d/e'
  239
+                , 'a/b/.x'
  240
+                , 'a/b/.x/'
  241
+                , 'a/.x/b'
  242
+                , '.x'
  243
+                , '.x/'
  244
+                , '.x/a'
  245
+                , '.x/a/b'
  246
+                , 'a/.x/b/.x/c'
  247
+                , '.x/.x' ]
  248
+    }
  249
+    , ["**/.x/**", [ '.x/'
  250
+                   , '.x/a'
  251
+                   , '.x/a/b'
  252
+                   , 'a/.x/b'
  253
+                   , 'a/b/.x/'
  254
+                   , 'a/b/.x/c'
  255
+                   , 'a/b/.x/c/d'
  256
+                   , 'a/b/.x/c/d/e' ] ]
  257
+
234 258
     ].forEach(function (c) {
235 259
       if (typeof c === "function") return c()
236 260
       if (typeof c === "string") return t.comment(c)
2  package.json
@@ -39,7 +39,7 @@
39 39
     "slide": "1",
40 40
     "abbrev": "1",
41 41
     "graceful-fs": "~1.1.1",
42  
-    "minimatch": "~0.2.6",
  42
+    "minimatch": "~0.2.8",
43 43
     "nopt": "~2.0",
44 44
     "rimraf": "2",
45 45
     "request": "~2.9",

0 notes on commit 5fd8258

Please sign in to comment.
Something went wrong with that request. Please try again.