isaacs / minimatch

a glob matcher in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

minimatch('/foo', '*/foo') => false

nodece opened this issue · comments

I expected the minimatch('/foo', '*/foo')=>true, but got false, I tried the micromatch, and picomatch returns true.

I wonder if I missed a configuration, thank you for your help!

* has to find something in that path portion. So */foo would match bar/foo, but not /foo.

Thank you for your answer! This project is awesome!

I'm using the picomath in the casbin, but I want to switch to this project, but this project doesn't support this case, I consider how to fix this case.

Thanks, I'm glad you like it!

Yeah, picomatch is more optimized for speed, and does take a few liberties with "correctness" in some cases to achieve that. Or, I guess a more fair way to put it is that it just has a different view of "correctness" than minimatch does, targeting behavior more like fnmatch rather than shell globbing semantics. It's impressively fast, though.

I still a question, I check some documentation, I find the following description.

  •   - (asterisk, star) matches zero or more of any characters
    

This means the */foo includes /foo. Is it right?

Zero or more characters, but the total path portion must be at least one character, and not start with a dot. Try testing it on a bash shell.

Ie echo a/*/foo* will match against a/x/foo.txt and a/x/foo, but not a/foo or a/foo.txt.

Ok, thanks.

My requirement should be path match with glob pattern. I am looking for ways to migrate to minimatch, because minimatch doesn't include the Node.js module, which is I need. I'll think about what I'm going to do.

If you want to match zero or more path portions, maybe what you're looking for is **/foo?

If you want to match zero or more path portions, maybe what you're looking for is **/foo?

This is right, but I want to using the * instead of **.

The following is my cases:

function globMatch(s: , patter: string) {
  return minimatch(s, patter);
}

test('test minimatch', () => {
  expect(globMatch('/foo', '*/foo')).toEqual(true);
  expect(globMatch('/foo', '*/foo*')).toEqual(true);
  expect(globMatch('/foo', '*/foo/*')).toEqual(false);
  expect(globMatch('/foo/bar', '*/foo/*')).toEqual(true);
  expect(globMatch('/foobar', '*/foo')).toEqual(false);
  expect(globMatch('/foobar', '*/foo*')).toEqual(true);
});

We already test these cases by https://pkg.go.dev/path#Match.

Yeah, I mean, it seems like you want fnmatch(3) style matching, not path expansion globs. That's not what this library is. 🤷

* doesn't match an empty path portion in shell expansion globs. echo */etc won't output /etc.