Skip to content

Different results from minimatch() function and Minimatch makeRe() #268

@SanderPs

Description

@SanderPs

I ran into this problem and it seems i am not the only one struggling with it, I even found another issue for it: 124.

But since I am using v10.0.3, and the hash in that issue points to changes already in master I thought it would be best to create a new issue.

This is reproduce code:

  const myFilePath = 'some-directory1/some-directory2/some-directory3/base.xsl';
  const myGlob = 'some-directory1/**/some-directory2/**/*.xsl';
  console.log('Check 1: ', minimatch(myFilePath, myGlob));
  const myGlobRegex1 = new Minimatch(myGlob, { matchBase: false, nocase: true } as MinimatchOptions).makeRe();
  const myGlobRegex2 = new Minimatch(myGlob, { matchBase: true, nocase: true } as MinimatchOptions).makeRe();
  console.log('Check 2: ', myGlobRegex1 ? myGlobRegex1.test(myFilePath) : 'illegal regex');
  console.log('Check 3: ', myGlobRegex2 ? myGlobRegex2.test(myFilePath) : 'illegal regex');

And the output is:

Check 1:  true
Check 2:  false
Check 3:  false

For completeness sake, I added matchBase, but that does not seem to matter. Value of regex's are:

myGlobRegex1: /^some\-directory1(?:\/|\/(?:(?!(?:\/|^)\.).)*?\/)some\-directory2\/(?!\.)[^/]*?\.xsl$/i
myGlobRegex2: /^some\-directory1(?:\/|\/(?:(?!(?:\/|^)\.).)*?\/)some\-directory2\/(?!\.)[^/]*?\.xsl$/i

Note that some-directory{n} means a directory name, not some path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions