django-s3-storage icon indicating copy to clipboard operation
django-s3-storage copied to clipboard

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

Open alisspers opened this issue 5 years ago • 1 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.

https://github.com/etianen/django-s3-storage/blob/2748957667b84f4416a5c5c174887700fd2c7a65/django_s3_storage/storage.py#L205-L208

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)

alisspers avatar May 27 '19 10:05 alisspers

Seems sensible. I'd take a PR.

On Mon, 27 May 2019 at 11:58, Anders Lisspers [email protected] wrote:

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.

https://github.com/etianen/django-s3-storage/blob/2748957667b84f4416a5c5c174887700fd2c7a65/django_s3_storage/storage.py#L205-L208

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 https://bitbucket.org/david/django-storages/pull-requests/72/for-the-s3-and-s3boto-backends-the-url/diff )

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/etianen/django-s3-storage/issues/86?email_source=notifications&email_token=AABEKCGPU6CXTZIQ7M7KR6TPXO5EVA5CNFSM4HP22XQ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GWABPPA, or mute the thread https://github.com/notifications/unsubscribe-auth/AABEKCBIR36IYX4NSQH7H23PXO5EVANCNFSM4HP22XQQ .

etianen avatar May 28 '19 08:05 etianen