#15181 closed (fixed)
FileSystemStorage generates wrong URL when path contains special characters
Reported by: | e.generalov | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | dev |
Severity: | Keywords: | ||
Cc: | paulegan@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a model with models.FileField and admin interface. When I upload any file that contains special characters in the name (for example test#12.jpg
), then I can't to download it by link in the admin change form.
There is a bug in the FileSystemStorage URL generation algorithm. This doesn't escapes special characters. Therefore the '/media/test#12.jpg' URL is produced and browser treats #12.jpg as a fragment part.
I notice same bug in the https://github.com/sorl/sorl-thumbnail/blob/legacy/sorl/thumbnail/main.py#L96 too, where iri_to_uri() is used for filepath-to-uri convertion (this method gives a wrong result too).
Therefore I suggest to place such function in the django core (see the patch).
Attachments (1)
Change History (8)
by , 14 years ago
Attachment: | filepath_to_uri.patch added |
---|
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:2 by , 14 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
comment:6 by , 14 years ago
Cc: | added |
---|
NB: This change means that URLs stored in FileFields or ImageFields using the default storage are now handled differently.
Previously:
>>> from django.core.files.storage import DefaultStorage, settings >>> settings.configure(MEDIA_URL='http://localhost') >>> DefaultStorage().url('http://media/test') 'http://media/test'
Now:
>>> from django.core.files.storage import DefaultStorage, settings >>> settings.configure(MEDIA_URL='http://localhost') >>> DefaultStorage().url('http://media/test') 'http://localhost/http%3A//media/test'
comment:7 by , 14 years ago
@paulegan: For future reference, regressions should be opened as a new ticket, not as continuing discussion on a closed ticket. I've opened #15521 to track this.
Please don't set the triage stage to RFC as an anonymous user.