micromatch / nanomatch

Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but without support for extended globs (extglobs), posix brackets or braces, and with complete Bash 4.3 wildcard support: ("*", "**", and "?").
https://github.com/micromatch
MIT License
95 stars 20 forks source link

Trailing slash discrepancy with micromatch #20

Open sbellone opened 5 years ago

sbellone commented 5 years ago

Please describe the minimum necessary steps to reproduce this issue:

const micromatch = require('micromatch'); // version must be >= 4.0.1
console.log(micromatch(['/test/t/'], ['**/t/']));
// [ '/test/t/' ]
console.log(micromatch(['/test/t/'], ['**/t']));
// []

const nm = require('nanomatch');
console.log(nm(['/test/t/'], ['**/t/']));
// [ '/test/t/' ]
console.log(nm(['/test/t/'], ['**/t']));
// [ '/test/t/' ]

What is happening:

micromatch takes into account the trailing slash and do an exact match nanomatch doesn't take it into account and match even without trailing slash in the pattern

What should be happening instead?

Both libraries should be aligned on this behaviour. From this previous issue on micromatch about trailing slashes, I believe we will want the fix to be done here in nanomatch.

Additional info

As micromatch switched from nanomatch to picomatch in v4.x (during this refactor), micromatch's behaviour has actually changed between v3.1.10 and v4.0.1. It was previously behaving like nanomatch. Again, after reading the discussion about the trailing slashes linked above, I believe we want to keep its new behaviour, so an additional unit test could be added in micromatch to be sure to stay consistent in the future.

jonschlinkert commented 5 years ago

Both libraries should be aligned on this behaviour

Why?

sbellone commented 5 years ago

Oh, I assumed that because in the description it states to be "Similar to micromatch", and because they have been aligned until last week (as micromatch was depending on it, I imagine).

Also it's a matter of having consistent behaviours inside the lib itself actually. If I take an example similar to the one from the linked discussion, I get this behaviour:

const nm = require('nanomatch');
console.log(nm(['t/'], ['t/']));
// [ 't/' ]
console.log(nm(['t/'], ['t']));
// []