Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('minimatch tests:', function() {
// http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test
mm.makeRe('a*').should.eql(/^(?:(?=.)a[^/]*?)$/);
mm.makeRe('X*', {nonull: true}).should.eql(/^(?:(?=.)X[^/]*?)$/);
mm.makeRe('X*').should.eql(/^(?:(?=.)X[^/]*?)$/);
mm.makeRe('\\*', {nonull: true}).should.eql(/^(?:\*)$/);
mm.makeRe('\\**', {nonull: true}).should.eql(/^(?:(?=.)\*[^/]*?)$/);
mm.makeRe('\\*\\*', {nonull: true}).should.eql(/^(?:\*\*)$/);
mm.makeRe('b*/').should.eql(/^(?:(?=.)b[^/]*?\/)$/);
mm.makeRe('c*').should.eql(/^(?:(?=.)c[^/]*?)$/);
mm.makeRe('**').should.eql(/^(?:(?:(?!(?:\/|^)\.).)*?)$/);
mm.makeRe('\\.\\./*/').should.eql(/^(?:\.\.\/(?!\.)(?=.)[^/]*?\/)$/);
mm.makeRe('s/\\..*//').should.eql(/^(?:s\/(?=.)\.\.[^/]*?\/)$/);
// legendary larry crashes bashes
mm.makeRe('/^root:/{s/^[^:]*:[^:]*:([^:]*).*$/\\1/').should.eql(/^(?:\/\^root:\/\{s\/(?=.)\^[^:][^/]*?:[^:][^/]*?:\([^:]\)[^/]*?\.[^/]*?\$\/1\/)$/);
mm.makeRe('/^root:/{s/^[^:]*:[^:]*:([^:]*).*$/\\1/').should.eql(/^(?:\/\^root:\/\{s\/(?=.)\^[^:][^/]*?:[^:][^/]*?:\([^:]\)[^/]*?\.[^/]*?\$\/1\/)$/);
// character classes
mm.makeRe('[a-c]b*').should.eql(/^(?:(?!\.)(?=.)[a-c]b[^/]*?)$/);
mm.makeRe('[a-y]*[^c]').should.eql(/^(?:(?!\.)(?=.)[a-y][^/]*?[^c])$/);
mm.makeRe('a*[^c]').should.eql(/^(?:(?=.)a[^/]*?[^c])$/);
mm.makeRe('a[X-]b').should.eql(/^(?:(?=.)a[X-]b)$/);
mm.makeRe('[^a-c]*').should.eql(/^(?:(?!\.)(?=.)[^a-c][^/]*?)$/);
mm.makeRe('a\\*b/*').should.eql(/^(?:a\*b\/(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('a\\*?/*').should.eql(/^(?:(?=.)a\*[^/]\/(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('a*[^c]').should.eql(/^(?:a(?!\.)(?=.)[^/]*?(?!\.)(?=.)[^c])$/);
mm.makeRe('a[X-]b').should.eql(/^(?:a(?!\.)(?=.)[X-]b)$/);
mm.makeRe('[^a-c]*').should.eql(/^(?:(?!\.)(?=.)[^a-c][^/]*?)$/);
mm.makeRe('a\\*b/*').should.eql(/^(?:a\*b\/(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('a\\*?/*').should.eql(/^(?:a\%\/(?!\.)(?=.)[^/]\/(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('*\\\\!*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\\![^/]*?)$/);
mm.makeRe('*\\!*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\![^/]*?)$/);
mm.makeRe('*.\\*').should.eql(/^(?:(?!\.)(?=.)[^/]*?.\*)$/);
mm.makeRe('a[b]c').should.eql(/^(?:a(?!\.)(?=.)[b]c)$/);
mm.makeRe('a[\\b]c').should.eql(/^(?:a(?!\.)(?=.)[\b]c)$/);
mm.makeRe('a?c').should.eql(/^(?:\/(?!\.)(?=.)[^/]c)$/);
mm.makeRe('a\\*c').should.eql(/^(?:a\*c)$/);
mm.makeRe('').should.eql(/^(?:)$/);
// http://www.opensource.apple.com/source/bash/bash-23/bash/tests/glob-test
mm.makeRe('*/man*/bash.*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\/man(?!\.)(?=.)[^/]*?\/bash.[^/]*?)$/);
mm.makeRe('man/man1/bash.1').should.eql(/^(?:man\/man1\/bash\.1)$/);
mm.makeRe('a***c').should.eql(/^(?:a.*(?!\.)(?=.)[^/]*?c)$/);
mm.makeRe('a*****?c').should.eql(/^(?:a.*.*\/(?!\.)(?=.)[^/]c)$/);
// console.log(mm.makeRe('?*****??'));
mm.makeRe('*****??').should.eql(/^(?:.*.*\/(?!\.)(?=.)[^/][^/])$/);
// console.log(mm.makeRe('?*****?c'));
// console.log(mm.makeRe('?***?****c'));
// console.log(mm.makeRe('?***?****?'));
// console.log(mm.makeRe('?***?****'));
// // console.log(mm.makeRe('*******c'));
// // console.log(mm.makeRe('*******?'));
// // console.log(mm.makeRe('a*cd**?**??k'));
// // console.log(mm.makeRe('a**?**cd**?**??k'));
// // console.log(mm.makeRe('a**?**cd**?**??k***'));
// // console.log(mm.makeRe('a**?**cd**?**??***k'));
// // console.log(mm.makeRe('a**?**cd**?**??***k**'));
mm.makeRe('a\\*?/*').should.eql(/^(?:(?=.)a\*[^/]\/(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('*\\\\!*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\\\![^/]*?)$/);
mm.makeRe('*\\!*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\![^/]*?)$/);
mm.makeRe('*.\\*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\.\*)$/);
mm.makeRe('a[b]c').should.eql(/^(?:(?=.)a[b]c)$/);
mm.makeRe('a[\\b]c').should.eql(/^(?:(?=.)a[b]c)$/);
mm.makeRe('a?c').should.eql(/^(?:(?=.)a[^/]c)$/);
mm.makeRe('a\\*c').should.eql(/^(?:a\*c)$/);
mm.makeRe('').should.be.false();
// http://www.opensource.apple.com/source/bash/bash-23/bash/tests/glob-test
mm.makeRe('*/man*/bash.*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\/(?=.)man[^/]*?\/(?=.)bash\.[^/]*?)$/);
mm.makeRe('man/man1/bash.1').should.eql(/^(?:man\/man1\/bash\.1)$/);
mm.makeRe('a***c').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/]*?c)$/);
mm.makeRe('a*****?c').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/);
mm.makeRe('?*****??').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/);
mm.makeRe('*****??').should.eql(/^(?:(?!\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/);
mm.makeRe('?*****?c').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/);
mm.makeRe('?***?****c').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/);
mm.makeRe('?***?****?').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/);
mm.makeRe('?***?****').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/);
mm.makeRe('*******c').should.eql(/^(?:(?!\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c)$/);
mm.makeRe('*******?').should.eql(/^(?:(?!\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/])$/);
mm.makeRe('a*cd**?**??k').should.eql(/^(?:(?=.)a[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/);
mm.makeRe('a**?**cd**?**??k').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/);
mm.makeRe('a**?**cd**?**??k***').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k[^/]*?[^/]*?[^/]*?)$/);
mm.makeRe('a**?**cd**?**??***k').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k)$/);
mm.makeRe('a**?**cd**?**??***k**').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k[^/]*?[^/]*?)$/);
mm.makeRe('a****c**?**??*****').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/);
mm.makeRe('[-abc]').should.eql(/^(?:(?!\.)(?=.)[-abc])$/);
mm.makeRe('[abc-]').should.eql(/^(?:(?!\.)(?=.)[abc-])$/);
mm.makeRe('\\').should.eql(/^(?:\\)$/);
mm.makeRe('a*[^c]').should.eql(/^(?:(?=.)a[^/]*?[^c])$/);
mm.makeRe('a[X-]b').should.eql(/^(?:(?=.)a[X-]b)$/);
mm.makeRe('[^a-c]*').should.eql(/^(?:(?!\.)(?=.)[^a-c][^/]*?)$/);
mm.makeRe('a\\*b/*').should.eql(/^(?:a\*b\/(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('a\\*?/*').should.eql(/^(?:(?=.)a\*[^/]\/(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('*\\\\!*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\\\![^/]*?)$/);
mm.makeRe('*\\!*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\![^/]*?)$/);
mm.makeRe('*.\\*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\.\*)$/);
mm.makeRe('a[b]c').should.eql(/^(?:(?=.)a[b]c)$/);
mm.makeRe('a[\\b]c').should.eql(/^(?:(?=.)a[b]c)$/);
mm.makeRe('a?c').should.eql(/^(?:(?=.)a[^/]c)$/);
mm.makeRe('a\\*c').should.eql(/^(?:a\*c)$/);
mm.makeRe('').should.be.false();
// http://www.opensource.apple.com/source/bash/bash-23/bash/tests/glob-test
mm.makeRe('*/man*/bash.*').should.eql(/^(?:(?!\.)(?=.)[^/]*?\/(?=.)man[^/]*?\/(?=.)bash\.[^/]*?)$/);
mm.makeRe('man/man1/bash.1').should.eql(/^(?:man\/man1\/bash\.1)$/);
mm.makeRe('a***c').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/]*?c)$/);
mm.makeRe('a*****?c').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/);
mm.makeRe('?*****??').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/);
mm.makeRe('*****??').should.eql(/^(?:(?!\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/);
mm.makeRe('?*****?c').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/);
mm.makeRe('?***?****c').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/);
mm.makeRe('?***?****?').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/);
mm.makeRe('?***?****').should.eql(/^(?:(?!\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/);
mm.makeRe('*******c').should.eql(/^(?:(?!\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c)$/);
mm.makeRe('*******?').should.eql(/^(?:(?!\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/])$/);
mm.makeRe('a*cd**?**??k').should.eql(/^(?:(?=.)a[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/);
mm.makeRe('a**?**cd**?**??k').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/);
mm.makeRe('a**?**cd**?**??k***').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k[^/]*?[^/]*?[^/]*?)$/);
mm.makeRe('a**?**cd**?**??***k').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k)$/);
mm.makeRe('a**?**cd**?**??***k**').should.eql(/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k[^/]*?[^/]*?)$/);
// nocase tests
mm.makeRe('XYZ', { nocase: true, null: true }).should.eql(/^(?:(?=.)XYZ)$/i);
mm.makeRe('ab*').should.eql(/^(?:(?=.)ab[^/]*?)$/);
mm.makeRe('ab*', { nocase: true, null: true }).should.eql(/^(?:(?=.)ab[^/]*?)$/i);
mm.makeRe('[ia]?[ck]').should.eql(/^(?:(?!\.)(?=.)[ia][^/][ck])$/);
// onestar/twostar
mm.makeRe('{/*,*}').should.eql(/^(?:\/(?!\.)(?=.)[^/]*?|(?!\.)(?=.)[^/]*?)$/);
mm.makeRe('{/?,*}').should.eql(/^(?:\/(?!\.)(?=.)[^/]|(?!\.)(?=.)[^/]*?)$/);
// dots should not match unless requested
mm.makeRe('**').should.eql(/^(?:(?:(?!(?:\/|^)\.).)*?)$/);
mm.makeRe('a/*/b').should.eql(/^(?:a\/(?!\.)(?=.)[^/]*?\/b)$/);
mm.makeRe('a/*/b', {dot: true}).should.eql(/^(?:a\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?\/b)$/);
mm.makeRe('a/.*/b').should.eql(/^(?:a\/(?=.)\.[^/]*?\/b)$/);
mm.makeRe('a/.*/b', {dot: true}).should.eql(/^(?:a\/(?=.)\.[^/]*?\/b)$/);
mm.makeRe('a/*/b').should.eql(/^(?:a\/(?!\.)(?=.)[^/]*?\/b)$/);
mm.makeRe('a/*/b', {dot: true}).should.eql(/^(?:a\/(?!(?:^|\/)\.{1,2}(?:$|\/))(?=.)[^/]*?\/b)$/);
mm.makeRe('a/.*/b').should.eql(/^(?:a\/(?=.)\.[^/]*?\/b)$/);
mm.makeRe('a/.*/b', {dot: true}).should.eql(/^(?:a\/(?=.)\.[^/]*?\/b)$/);
mm.makeRe('**').should.eql(/^(?:(?:(?!(?:\/|^)\.).)*?)$/);
mm.makeRe('**', {dot: true}).should.eql(/^(?:(?:(?!(?:\/|^)(?:\.{1,2})($|\/)).)*?)$/);
// paren sets cannot contain slashes
mm.makeRe('*(a/b)').should.eql(/^(?:(?!\.)(?=.)[^/]*?\(a\/b\))$/);
mm.makeRe('*(a|{b),c)}').should.eql(/^(?:(?!\.)(?=.)(?:a|b)*|(?!\.)(?=.)(?:a|c)*)$/);
mm.makeRe('[!a*').should.eql(/^(?:(?=.)\[(?=.)\!a[^/]*?)$/);
mm.makeRe('[#a*').should.eql(/^(?:(?=.)\[(?=.)#a[^/]*?)$/);
mm.makeRe('+(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g').should.eql(/^(?:(?=.)\+\(a\|[^/]*?\|c\\\\\|d\\\\\|e\\\\\\\\\|f\\\\\\\\\|g)$/);
mm.makeRe('*(a|{b,c})').should.eql(/^(?:(?!\.)(?=.)(?:a|b)*|(?!\.)(?=.)(?:a|c)*)$/);
mm.makeRe('{a,*(b|c,d)}').should.eql(/^(?:a|(?!\.)(?=.)[^/]*?\(b\|c|d\))$/);
it('should use special characters and glob stars together:', function() {
mm.makeRe('a/?/c/?/*/e.md').test('a/b/c/d/e.md').should.be.false();
mm.makeRe('a/?/c/?/*/e.md').test('a/b/c/d/e/e.md').should.be.true();
mm.makeRe('a/?/c/?/*/e.md').test('a/b/c/d/efghijk/e.md').should.be.true();
mm.makeRe('a/?/**/e.md').test('a/b/c/d/efghijk/e.md').should.be.true();
mm.makeRe('a/?/**/e.md').test('a/bb/c/d/efghijk/e.md').should.be.false();
mm.makeRe('a/*/?/**/e.md').test('a/b/c/d/efghijk/e.md').should.be.true();
mm.makeRe('a/*/?/**/e.md').test('a/b/c/d/efgh.ijk/e.md').should.be.true();
mm.makeRe('a/*/?/**/e.md').test('a/b.bb/c/d/efgh.ijk/e.md').should.be.true();
mm.makeRe('a/*/?/**/e.md').test('a/bbb/c/d/efgh.ijk/e.md').should.be.true();
});
});
it('should create a regular expression for file paths:', function() {
mm.makeRe('**/*.js').test('a/b.js').should.be.true();
mm.makeRe('**/*.js').test('b.js').should.be.true();
mm.makeRe('*.js').test('a/b.js').should.be.false();
mm.makeRe('*.js').test('a.js').should.be.true();
mm.makeRe('a/b/c/*.md').test('.gitignore').should.be.false();
mm.makeRe('a/b/c/*.md').test('.gitignore.md').should.be.false();
mm.makeRe('a/b/c/*.md').test('a/b/c/d.gitignore.md').should.be.true();
mm.makeRe('a/b/c/*.md').test('a/b/d/.gitignore').should.be.false();
mm.makeRe('a/b/c/*.md').test('a/b/c/xyz.md').should.be.true();
mm.makeRe('a/*/c/*.md').test('a/bb/c/xyz.md').should.be.true();
mm.makeRe('a/*/c/*.md').test('a/bbbb/c/xyz.md').should.be.true();
mm.makeRe('a/*/c/*.md').test('a/bb.bb/c/xyz.md').should.be.true();
mm.makeRe('a/**/c/*.md').test('a/bb.bb/aa/bb/aa/c/xyz.md').should.be.true();
mm.makeRe('a/**/c/*.md').test('a/bb.bb/aa/b.b/aa/c/xyz.md').should.be.true();
});
});
it('should create a regex for matching dotfiles:', function() {
mm.makeRe('*.md').test('a.md').should.be.true();
mm.makeRe('*.*.md').test('.foo.md').should.be.false();
mm.makeRe('!*.*.md').test('.foo.md').should.be.true();
mm.makeRe('*.*.md').test('a.foo.md').should.be.true();
mm.makeRe('*.md').test('.gitignore').should.be.false();
mm.makeRe('.gitignore').test('.gitignore').should.be.true();
mm.makeRe('!.gitignore').test('.gitignore').should.be.false();
mm.makeRe('*.md').test('.verb.txt').should.be.false();
mm.makeRe('a/b/c/.*.md').test('a/b/c/.xyz.md').should.be.true();
});
});
.add('minimatch', () => mm.makeRe('**'))
.run();
ignorePaths.forEach((ignorePath) => {
const ignore = require("minimatch").makeRe(ignorePath, {
"dot": true,
"nocomment": true
});
if (ignore) {
ignores.push(ignore);
}
});
}