Skip to content

Removes special characters from temporary filenames#2480

Merged
abidlabs merged 4 commits into
mainfrom
file-hashes
Oct 18, 2022
Merged

Removes special characters from temporary filenames#2480
abidlabs merged 4 commits into
mainfrom
file-hashes

Conversation

@abidlabs
Copy link
Copy Markdown
Member

Removes special characters from temporary filenames so that the files can be served by components.

Closes: #2468

@github-actions
Copy link
Copy Markdown
Contributor

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2480-all-demos

Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Looks good to me @abidlabs ! Thanks for the fix.

Comment thread gradio/processing_utils.py Outdated
Comment thread gradio/processing_utils.py
@abidlabs
Copy link
Copy Markdown
Member Author

Thanks for the review @freddyaboulton! Used this excuse to organize the test\test_processing_utils.py a bit

@abidlabs abidlabs merged commit 081f63c into main Oct 18, 2022
@abidlabs abidlabs deleted the file-hashes branch October 18, 2022 19:58
@ColtonBehannon
Copy link
Copy Markdown

I am curious if there is any way to still get the special characters out of the file names with fileobj.name? If I want my application to be able to upload that same file to other resources such Azure Storage Explorer I need to be able to access the original file name but the current workflow appears to remove special characters such as the "()" in test_file(1).txt.

@abidlabs
Copy link
Copy Markdown
Member Author

abidlabs commented Sep 29, 2023

Not possible at the moment @ColtonBehannon since these are stripped. Is it possible for you to strip the same special characters on your end to reconcile the file names?

@ColtonBehannon
Copy link
Copy Markdown

@abidlabs Thanks for the quick response! I think that could work though I'm not sure what all characters are considered special in this context and would need to be stripped. For example, are underscores included as well or not. Any suggestions here other than testing them all?

@abidlabs
Copy link
Copy Markdown
Member Author

Here's the logic:

filename = "".join([char for char in filename if char.isalnum() or char in "._- "])

so yes underscores are valid

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.

File paths not properly escaped in /file route, causing RuntimeError (file does not exist)

3 participants