glob icon indicating copy to clipboard operation
glob copied to clipboard

Various bugs

Open aiurovet opened this issue 3 years ago • 4 comments

Summary (I did not check on Linux, but hopefully, matching there is case-sensitive):

  • Escaping: no check on escaped forward-slash or escape character itself in the pattern: / or \ (yes, I understand that these are weird, but still legitimate - throw an exception at least)
  • Escaping: if you support that, then any character must be escapable, and if someone wants to have a backslash as path separator, they should double that: \ (but / instead is legitimate anyway)
  • Current directory and relative paths are not considered, and if the current drive is specified, not all absolute paths match: C:\ fails to match /
  • Path separator assumed to be outside any kind of brackets
  • Crashed for complex braces like: **/{.md,src/.cs}

Details (YES = all good):

Current Directory: C:\Users\AlexIurovetski\Projects\Dabble\Dabble\bin\Debug\net6.0

Glob:  c:\a\b\..\b\*.cs
Path:  c:\a\b\c.cs
Match: -- NO --

Glob:  **/*.cs
Path:  c:\a\b\c.cs
Match: YES

Glob:  **\*.cs
Path:  c:\a\b\c.cs
Match: YES

Glob:  **.cs
Path:  c:\a\b\c.cs
Match: YES

Glob:  \**\*.cs
Path:  c:\a\b\c.cs
Match: -- NO --

Glob:  *.{cs,txt}
Path:  c:\a\b\c.cs
Match: YES

Glob:  **/{*.md,src/*.cs}
Path:  c:\a\b\c.cs
Match: -- CRASHED --

Glob:  **[/\]*.cs
Path:  c:\a\b\c.cs
Match: -- NO --

aiurovet avatar Jun 22 '22 06:06 aiurovet

What version are you using?

kthompson avatar Jun 22 '22 14:06 kthompson

I took the latest stable from NuGet

aiurovet avatar Jun 22 '22 15:06 aiurovet

So based on 1.1.9 and your failing test cases:


Directory traversal in glob patterns is not supported and I don't think it makes sense to do that:

Glob:  c:\a\b\..\b\*.cs
Path:  c:\a\b\c.cs
Match: -- NO --

throws GlobPatternException Unexpected character * at index 4 since the specified format is not supported. See the README for supported expressions https://github.com/kthompson/glob#expressions

Glob:  **/{*.md,src/*.cs}
Path:  c:\a\b\c.cs
Match: -- CRASHED --

This pattern is weird. Just use / for directory pattern matching this works on Windows and Linux. In this case the pattern should be **/*.cs this will work on Windows/Mac/Linux

Glob:  **[/\]*.cs
Path:  c:\a\b\c.cs
Match: -- NO --

Roots are treated specially between windows and linux/mac. In the Mac/Linux case this would work fine but a starting / indicates a specific root. If you want to match on any drive just use **/*.cs if you want to match on a specific drive then use c:/**/*.cs(Windows) or /**/*.cs(*nix) for your pattern.

Glob:  \**\*.cs
Path:  c:\a\b\c.cs
Match: -- NO --

In addition escaping is not supported on 1.1.9. The pre-release versions have support for escaping glob characters. Extended glob expressions are also not supported.

kthompson avatar Jun 22 '22 15:06 kthompson

OK. You can close the ticket.

Sorry, I forgot to check before, but today I found that the filename abc.cs matches both **.cs and **/*.cs although the latter should fail. See GNU documentation: section globstar in https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html

aiurovet avatar Jun 23 '22 08:06 aiurovet