Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF-8 compatibility fix broke serving filenames with spaces #26

Closed
MRigal opened this issue Sep 2, 2014 · 9 comments
Closed

UTF-8 compatibility fix broke serving filenames with spaces #26

MRigal opened this issue Sep 2, 2014 · 9 comments

Comments

@MRigal
Copy link

MRigal commented Sep 2, 2014

Hi all,

Updating from 0.3.4 to 0.3.6, I had the bad surprise to see that it broke the support of files containing whitespaces.

The response of sendfile 0.3.4 for such a file was :
X-Accel-Redirect: /protected_files/1/files/Backup 2014-09-02-2.sqlbackup
Content-length: 70458
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="Backup 2014-09-02-2.sqlbackup.zip"

And now (since 0.3.5) it is:
X-Accel-Redirect: /protected_files/1/files/Backup%202014-09-02-2.sqlbackup
Content-length: 70458
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="Backup 2014-09-02-2.sqlbackup.zip"

Which makes the download fail...

Best,
Matthieu

@MRigal
Copy link
Author

MRigal commented Sep 2, 2014

And if somebody wants to see the difference between the versions, as it is just a bit of utf8 encoding: 629df02...master

@stevelacey
Copy link

+1 I am also seeing problems with files with spaces

@johnsensible
Copy link
Owner

Any suggestions on how to deal with this? I'm not 100% sure what needs to be done?

It's been a while since I've done anything on this project.

It actually looks like the latest version doesn't doing any utf8 encoding at all?

https://github.com/johnsensible/django-sendfile/blob/master/sendfile/backends/nginx.py

But I can see in @MRigal example that the filename appears to be URL encoded (e.g. %20 instead of a space).

p.s. sorry for not replying to this sooner. This ticket appeared one day after the birth of my 2nd child. Still playing catchup...

@MRigal
Copy link
Author

MRigal commented Mar 19, 2015

OK, I'll try to write a proper test and take a look at that in the next days. It doesn't seem that trivial, especially when willing to have Python 2 and 3 support.

johnsensible added a commit that referenced this issue May 5, 2015
No longer using urlquote.  Insteading actually encoding to utf8 bytes.

Fixes #35, #26
@johnsensible
Copy link
Owner

I've just put a fix in for this. It's currently just in the master branch. Am now encoding the filenames to utf8 bytes (as per http://stackoverflow.com/questions/2732268/django-unicode-filenames-with-ascii-headers), rather than using urlquote.

I've updated the tests etc for this, but it would be good if people can actually try this out to make sure it does actually work...

@johnsensible
Copy link
Owner

Once I know it's working I'll package up a new release for PyPi.

@philipdouglas
Copy link

That fix works for the problem with @s I reported in #35.

@johnsensible
Copy link
Owner

Ok, think I'm just going to package this up and put it on PyPi then.

@johnsensible
Copy link
Owner

Ok 0.3.7 is on PyPi now:

https://pypi.python.org/pypi/django-sendfile/0.3.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants