etianen / django-s3-storage

Django Amazon S3 file storage.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The url() method strips trailing slash from the given name

alisspers opened this issue · comments

We're using the plugin django-ckeditor to add a wysiwyg editor to our models. The package fails to load its static files when used together with django-s3-storage, because of a lost slash when constructing the URL that ends up looking something like this:

https://[my-bucket].s3.eu-central-1.amazonaws.com/ckeditor/ckeditorconfig.js?

while it's supposed to look like this:

https://[my-bucket].s3.eu-central-1.amazonaws.com/ckeditor/ckeditor/config.js?

(notice the missing slash before config.js)

This happens because django-ckeditor calls url() with the name 'ckeditor/ckeditor/', and somewhere along the way this trailing slash is removed.

I've drilled it down to being the _get_key_name that strips the trailing slash.

def _get_key_name(self, name):
if name.startswith("/"):
name = name[1:]
return posixpath.normpath(posixpath.join(self.settings.AWS_S3_KEY_PREFIX, _to_posix_path(name)))

It's using posix.normpath which by design strips trailing slashes.

A proposed solution would be to readd the trailing slash after running normpath (much like the PR in the "sister package" django-storage)