Robert-van-Engelen / FastGlobbing

Faster and safer algorithms for string matching with wildcards, globs, and gitignore-style globs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can you explain, please, the behavior of the dot?

mxmauro opened this issue · comments

Hi, I really appreciate your work. Was looking for a glob pattern matching using double stars until found this gem.

But I'm having troubles to understand the behavior of the dot character. I'm trying to use the code on Windows but converted to *nix style for convenience.

const glob = require("./glob");

glob.dotglob = false;

if (glob.gitignore_glob_match("/windows/system32/reg.exe", "**/.exe")) {
	console.log("match");
}
else {
	console.log("mismatch");
}

glob.dotglob = true;

if (glob.gitignore_glob_match("/windows/system32/reg.exe", "**/.exe")) {
	console.log("match");
}
else {
	console.log("mismatch");
}

In both cases, I would expect a mismatch because the base name. Tracing the code, the **/ loops and ends skipping the dots in both text and pattern in the switch's default.

Is this the expected behavior?

Kind regards,
Mauro.

Hmm. This looks odd to me.

./match '/windows/system32/reg.exe' '**/.exe'
naive recursive match = N
recursive match       = N
match                 = N
globly match          = N
glob match            = N
gitignore glob match  = Y

Should be fixed now.

Thank you. Very much! I'll try it.

Kind regards.

I've made one more small improvement to handle leading / in directory paths when matched with **/foo globs. These changes are tiny modifications to the logic when matching the next character after **/, which caused the issue you saw. Thanks for reporting.

You are welcome. Saw the code. A minor issue, in the JS version, the comparison is === but in the rest, it is !=.

I'll give a check on Windows later, adding the drive-letter colon at the beginning.

Hi @Robert-van-Engelen , tested on Windows' paths and worked perfectly.

Just a minor thing: There is a typo in JS code, line 180, it says text.chatAt instead of text.charAt

Kind regards and thanks again.