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.
This PR attempts to resolve #3124 by encoding any special characters in URLs auto-generated from file names. This was done by adding
urllib.parse.quote()
toapp.add_media_file()
andapp.add_static_file()
.The only difficult question was whether or not to also encode caller-provided URLs. Since
url_path
must be supplied in unencoded form to work with the FastAPI decorator, there should be no risk of double-encoding. The only downside of encoding it is that if a user passes in anurl_path
that includes special characters and relies on the return value being the same unencoded string, it could break their code.Since this is a pretty narrow edge case, I opted for this behavior to keep the operation of the methods more consistent. If you'd rather go the more conservative route of just returning the
url_path
provided value unencoded, that's obviously a simple change. However, then the return value description would have to be more complicated to fully describe the behavior.