#9586: Shall upload_to return an urlencoded string or not? -------------------------------------------+-------------------------------- Reporter: eibaan | Owner: nobody Status: new | Milestone: Component: File uploads/storage | Version: 1.0 Resolution: | Keywords: Stage: Unreviewed | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | -------------------------------------------+-------------------------------- Comment (by eibaan):
Analysis: I checked {{{django.core.files.storage}}} and I think, my problem roots in that {{{FileSystemStorage.url()}}} does not create URLs. This is the point where the contract (or at least my expectation) is broken. {{{urlparse.urljoin()}}} is expecting URL segments but a filename is passed, that may contain spaces or other special characters that would need to be escaped. Futhermore, on non-windows platforms where \ is a valid (even if uncommon) character, it is replaced with a slash so that a cleverly named file can provide access to subfolders you might not want to be accessible. I think, a better implementation would be this: {{{ url = "/".join(map(urlquote, name.split(os.path.sep))) return urlparse.urljoin(self.base_url, url) }}} I find it irritating that {{{Storage.save()}}} replaces \ with /, perhaps as a poor man's attempt to make it an URL? Why not honor the operation system's conventions here? If at all, this belongs IMHO into the {{{FileSystemStorage}}} and not in the generic class. The method {{{Storage.get_valid_name()}}} kills both \ and / even if other methods assume/accept them. It also restricts the set of valid characters to a-z, ignoring all other letters and removes spaces and other punctuations. Removing all but 26 letters might be ok for western countries (but even I need full unicode support) but I imagine it is inacceptable for for example Russian or Greek speaking countries. This method hides the problems with that other methods because it restricts everything to a ASCII subset. If you create your own {{{upload_to}}} method, you circumvent that method call and feed "real" file names into that other methods which causes the described problems. -- Ticket URL: <http://code.djangoproject.com/ticket/9586#comment:2> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---