glob-to-regexp
glob-to-regexp copied to clipboard
The idea of converting globs to regexes is a good one
The idea of converting globs to regexes is a good one. However, the conversion done by this code is not correct. Using /^..min.js$/ as the regex for ".min.js" is wrong. The dot asterisk (.*) after the carrot will match all characters including forward slashes. That is not how globs are supposed to work. Wikipedia (and other sources) says that a glob asterisk does not match any forward slashes.
Note that re = globToRegExp("*.min.js"); re.test("http://example.com/jquery.min.js"); // true
is wrong. The asterisk should match "jquery" but not "example/jquery". A globstar (two asterisks) does match slashes, but not a single asterisk. The full rules for a globstar are more complex than I have stated here.