Handle uploading filenames with special characters #640
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when a user tries to upload a filename such as “slide(1).svs”, Slideloader will save it as “slide1.svs” and tell the frontend about this. This happens when finalizing an upload. However the frontend discards this information and after finalizing, validates by calling the metadata API of “slide(1).svs”, which returns “Not found”, and the user never reaches the “success” stage.
Summary
Firstly, the frontend should display the sanitized filename on upload finalization, and use this filename for validation.
Secondly, the frontend should also replace the filename with the sanitized one when starting upload.
Doing these both will give us good UX so that we won’t need to list: “the filename cannot contain (,), … etc”, but the user’s entered input will have these removed automatically and the user will understand instinctively that some characters aren’t allowed and will be removed.
Motivation
Many filenames have special characters and this needs to be handled correctly
Testing
I tested this patch with the following:
Filename with no special chars
Filename with ( or any other char
Filename with # (because this would be a special case if treated as a part of a URL)
The previous two cases, but now the user added the special chars after the original filename didn’t have them
Again, this time the user readded them after initial sanitizing
Filename with only special chars and extension
The previous but the user made it so after choosing a valid filenamed upload
Filename whose sanitization leads to conflict with a previous one
The previous but the original filename wouldn’t
Questions
Say anIn short, I thought it's best to not allow redundant queries to the backend in this case, since people, most likely those who would like to explor edge cases of caMicroscope, who would like to uploada.svsfile already exists. The user would like to uploada.Svs. caMicroscope will replace the textbox witha.svsand say: "a.svs already exists!" The user then thinks, "No, I really want a.Svs and this is a different file!" The frontend same-query filtering will not show and error message or generate requests and the user won't proceed until he picks a different filename.a.svs a.Svs a.SvS a.sVs a.sVS ...as different files are rare.EDIT: I have now also added the patch for the batch loader