Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace reserved chars in filenames #138

Merged
merged 3 commits into from
Mar 29, 2023

Conversation

spiess-demos
Copy link
Contributor

@spiess-demos spiess-demos commented Mar 29, 2023

Ticket: https://yaits.demos-deutschland.de/T31971

As the tus endpoint breaks with 400 when uploading files with certain characters within them, the fileName is cleaned from those malfunctioning characters before adding it to the Uppy store (and eventually uploading them, as auto resume is activated).

The characters to be replaced were chosen based on a manual test that i conducted - while i could not produce a file containing a forward slash on my linux machine, all other characters have proven to break the endpoint. Maybe i missed a character, then it will have to be added to the list.

The fix actually only changes the file name in the outermost file.name, and within file.meta.name, whereas it leaves the original file name within data.File.name (which is an instance of the File API and also preserves the original name within its prototype). Somehow this leads to the unchanged file name being displayed correctly after uploading has finished. As such, there can be said that the bug has not been understood from a backend perspective.

The fix revealed another bug - file names containing a colon : now broke the frontend, because the colon is used as a separator in getFileInfo. As the conversion (from object to fileString and vice versa) is not needed but is a remainder from the Uppy refactoring (as far as i could understand it), it is dropped altogether, and the file object is directly passed into DpUploadFile.

As the tus endpoint breaks with 400 when uploading files with
certain characters within them, the fileName is cleaned from
those malfunctioning characters before adding it to the Uppy store
(and eventually uploading them, as auto resume is activated).

The characters to be replaced were chosen based on a manual test
that i conducted - while i could not produce a file containing
a forward slash on my linux machine, all other characters have
proven to break the endpoint. Maybe i missed a character, then
it will have to be added to the list.

The fix revealed another bug - file names containing a colon :
now broke the frontend, because the colon is used as a separator
in getFileInfo. As the conversion (from object to fileString and
vice versa) is not needed but is a remainder from the Uppy refactoring
(as far as i could understand it), it is dropped altogether, and the
file object is directly passed into DpUploadFile.
Comment on lines 127 to 131
/*
* For reasons i could not figure out, the for loop was needed here
* to reliably access the item that is looped over. When using forEach,
* strangely it always held the value of currentFile.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since its totally fine to use a for-loop, I suggest to drop the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in case somebody wants to optimize it, they'll be warned, if we leave the comment there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I am against that. Then we have to argue all our code in comments....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, removed in 5c6ee11

src/components/core/DpUpload/DpUpload.vue Show resolved Hide resolved
@spiess-demos spiess-demos merged commit 1823490 into main Mar 29, 2023
@spiess-demos spiess-demos deleted the b_T31971_replace_reserved_chars_in_filenames branch March 29, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants