dazinator / DotNet.Glob

A fast globbing library for .NET / .NETStandard applications. Outperforms Regex.
MIT License
363 stars 27 forks source link

What characters does the default setting allow in a file/folder path/name? #60

Closed kunalkaroth closed 6 years ago

kunalkaroth commented 6 years ago

On Windows, special file characters: \, /, :, , ?, ", |, <, > are not allowed for file / folder names. On NIX/MAC, special file characters: \0, / are not allowed.

I hope the library honours this? :)

dazinator commented 6 years ago

You can see https://github.com/dazinator/DotNet.Glob/issues/52 for some history on this. by honour I think you mean that it shouldn't allow you to construct glob patterns that have characters that are invalid for the file system of the platform you are running on? Is that right? If so - it used to have this as a setting and would throw an exception if an invalid character was specified in the glob pattern. The problem with this setting is that the "allowable" file path characters differs a lot from platform to platform and was very confusing and frustrating to get a definitive answer too. Also, globbing on file system paths is not the only use case, I have seen people using this library to glob against windows registry entries, or url's etc so this setting wasn't valuable in those cases. Technically I don't see much value in dotnet glob making any kind of assumption about the underlying input string - i.e assuming it will always be a file system path is unnecessary coupling in my opinion. The only case I can think of where this might be a problem is where you allow users to input their own glob pattern for a search against the local file system, and you construct a glob from it without doing any sanitisation to check for invalid file system characters. Is this the use case you have in mind? If so, it seems it could potentially be handled by sanitising the user's input first?

dazinator commented 6 years ago

Closing this for now. If this is causing you some sort of exception or problem please feel free to comment further and i'll reopen if necessary.

kunalkaroth commented 6 years ago

Thanks for the detailed explanation. On top of what you mention, there could be instances where windows is running on mac etc. In such cases the semantics become even more murkier. I agree with you. Thanks again.