Skip to content

Commit

Permalink
Do not throw on glob.hasMagic('')
Browse files Browse the repository at this point in the history
Fix #283
  • Loading branch information
isaacs committed Aug 24, 2016
1 parent 1728df8 commit 481abb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ glob.hasMagic = function (pattern, options_) {

var g = new Glob(pattern, options)
var set = g.minimatch.set

if (!pattern)
return false

if (set.length > 1)
return true

Expand Down
9 changes: 9 additions & 0 deletions test/has-magic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ test("create glob object without processing", function (t) {
t.end()
})

test("non-string pattern is evil magic", function (t) {
var patterns = [ 0, null, 12, {x:1}, undefined, /x/, NaN ]
patterns.forEach(function (p) {
t.throws('' + p, function () { glob.hasMagic(p) })
})
t.end()
})

test("detect magic in glob patterns", function (t) {
t.notOk(glob.hasMagic(""), "no magic in ''")
t.notOk(glob.hasMagic("a/b/c/"), "no magic a/b/c/")
t.ok(glob.hasMagic("a/b/**/"), "magic in a/b/**/")
t.ok(glob.hasMagic("a/b/?/"), "magic in a/b/?/")
Expand Down

0 comments on commit 481abb0

Please sign in to comment.