Deewiant / glob

Haskell library for glob matching
https://deewiant.iki.fi/projects/glob/
Other
25 stars 8 forks source link

Documentation for `**/` is confusing #47

Open brprice opened 2 years ago

brprice commented 2 years ago

The docs say "**/ Matches any number of characters, including path separators, excluding the empty string.", but this does not seem to match what I see in practice.

I see the following, where each M is a file

$ tree
.
├── A
│   └── M
├── B
│   ├── C
│   │   └── M
│   └── M
└── M

With zsh, for comparison, as that is what I traditionally associate this syntax with

$ echo **/
A/ B/ B/C/
$ echo **/M
A/M B/C/M B/M M

With Glob

System.FilePath.Glob> globDir1 (compile "**/") "."
["./A/","./B/"]
System.FilePath.Glob> globDir1 (compile "**/M") "."
["./A/M","./B/M","./B/C/M","./M"]
System.FilePath.Glob> match (compile "**/M") "M"
True
System.FilePath.Glob> match (compile "**/") "B/C/"
True

Notice:

The behaviour seems to be more akin to **/ will match any (potentially empty) sequence of directories, but may or may not match nested directories/be recursive based on some subtle details". This seems rather weird, so I doubt this is the actual behaviour. Some clarification on what this pattern does would be appreciated.

Deewiant commented 2 years ago

In addition to the documentation, it seems that the behaviour is wrong.

That first globDir1 should certainly return ./B/C/ as well; in general globDir1 pat should correspond exactly to a filter (match pat) over a recursive directory listing.

**/M matching "M" feels wrong, though I can't say for sure whether there may have been a reason for it. As you point out, it conflicts with the documentation at the very least.

In general zsh was the inspiration for the default behaviour so any conflicts are more likely than not to be a bug in Glob.