WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

Add file path validation to Object Storage helper

Open ThisWillDoIt opened this issue 9 years ago • 6 comments

Since checking if a file path is valid isn't trivial (checking for GetInvalidFileNameChars() is not sufficient) it would be nice if the storage helpers could validate the path itself or if there would be an separat helper.

ThisWillDoIt avatar Dec 07 '16 10:12 ThisWillDoIt

Ping @Odonno

deltakosh avatar Dec 07 '16 16:12 deltakosh

@ThisWillDoIt I am not sure I understand what you asked. You want to automatically check the parameter filePath when using ObjectStorage helper ?

Odonno avatar Dec 07 '16 16:12 Odonno

Yes, that is correct.

For example currently a string including an '#' throws an exception while some other special chars are allowed. In most cases the filePath string will come from the app developer, who can try if those characters are valid or not.

But maybe there are scenarios where some kind of user input is part of the name. Which characters have to be stripped out? Which are okay? In addition to illegal characters I read somewhere that there are special file names not allowed on windows systems.

As I said I am not sure if this should be part of the storage helper it self or an separat helper, but it would be really nice to have an easy way to check if a given name/path is valid. Something like bool IsPathValid(string filePath);

ThisWillDoIt avatar Dec 08 '16 23:12 ThisWillDoIt

I assume this method will be part of StorageFileHelper https://github.com/Microsoft/UWPCommunityToolkit/blob/dev/Microsoft.Toolkit.Uwp/Helpers/StorageFileHelper.cs

@ThisWillDoIt So, you only want a method to check if the path is valid or do you want it to be included in every method and throw an exception in case there is an illegal character ?

Odonno avatar Dec 09 '16 11:12 Odonno

I am not really sure what the best approach would be, but I like the thing you started, since exceptions can already be handled. Maybe a hint in the documentation which exceptiones can occur by calling this method would be good.

ThisWillDoIt avatar Dec 11 '16 15:12 ThisWillDoIt

The PR has been merged by @hermitdave. Thanks by the way.

@ThisWillDoIt I think it will fit your needs. If you have any troubles using the new methods or if you see something that goes wrong, I am sure we can see that together in the future.

Have fun!

Odonno avatar Jan 02 '17 20:01 Odonno