OpenArchive / Save-app-android-old

This is the Save app for Android
https://open-archive.org
GNU General Public License v3.0
93 stars 25 forks source link

Limit special characters on folder creation #569

Open ryjen opened 7 months ago

ryjen commented 7 months ago

Describe the bug Though possible, the one specification document found says not more than 1 folder deep.

Lets limit the available characters, like a normal operating system, including ~, ^, :, <,>, !, *, #, =, ., +, $,%, (,), ", ?, [], {}, and @.

To Reproduce Steps to reproduce the behavior:

  1. Create a new folder
  2. Enter '/' as a path or a special character
  3. Hit create

Expected behavior The application should report an invalid file path

Actual Behaviour The application allows anything, and gets converted to a URL encoded string.

Additional Context

In order to allow folder creation, we need better UX and to know how it applies across all backends.

tladesignz commented 7 months ago

Digging through the net, I remember, why I reserved this problem for another day:

https://www.mtu.edu/umc/services/websites/writing/characters-avoid/ https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names

There are tons of potentially illegal filenames. I despise the whitelist approach also, though. Users should be able to create folder names in Cyrilic, Thai, Kanji etc.

I'd want to add the following to your list:

And I'd like to add whitespace trim. Should we error that, or just remove them automatically?

Can we develop a regex expression here together to check against and show an error?

First attempt in straight Java8 notation without extra escaping:

[~^:<>!*#=.+$%()\"?\[\]\{\}@\/\\\&[:cntrl:]]

https://regex101.com