Skip to content

Commit

Permalink
Fix isaacs#4 Properly handle negation extglobs
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 22, 2012
1 parent d1484f1 commit 7d976b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions minimatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ function parse (pattern, isSub) {
patternListStack.push({ type: plType
, start: i - 1
, reStart: re.length })
re += stateChar === "!" ? "(?!" : "(?:"
// negation is (?:(?!js)[^/]*)
re += stateChar === "!" ? "(?:(?!" : "(?:"
stateChar = false
continue

Expand All @@ -532,11 +533,15 @@ function parse (pattern, isSub) {
hasMagic = true
re += ")"
plType = patternListStack.pop().type
// negation is (?:(?!js)[^/]*)
// The others are (?:<pattern>)<type>
switch (plType) {
case "!":
re += "[^/]*?)"
break
case "?":
case "+":
case "*": re += plType
case "!": // already handled by the start
case "@": break // the default anyway
}
continue
Expand Down
12 changes: 12 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ tap.test("basic tests", function (t) {
// anything that is NOT !a* matches
, ["!\\!a*", ["a!b", "d", "e", "\\!a"]]

// negation nestled within a pattern
, function () {
files = [ "foo.js"
, "foo.bar"
// can't match this one without negative lookbehind.
, "foo.js.js"
, "blar.js"
, "foo."
, "boo.js.boo" ]
}
, ["*.!(js)", ["foo.bar", "foo.", "boo.js.boo"] ]

].forEach(function (c) {
if (typeof c === "function") return c()
if (typeof c === "string") return t.comment(c)
Expand Down

0 comments on commit 7d976b6

Please sign in to comment.