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

handling defined filename encoding in Content-Disposition #1694

Closed
pawciobiel opened this Issue Mar 1, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@pawciobiel
Contributor

pawciobiel commented Mar 1, 2018

  • I'm submitting a ...
  • bug report
  • Do you want to request a feature or report a bug?
    I'd like to report a bug because this appears to me as undocumented and undesired behaviour,
    but I understand that this could also be feature request.

  • What is the current behavior?

When POSTing a file containing non ASCII characters in it's name, using Content-Type: multipart/form-data
and Content-Disposition with defined encoding:

form-data; name="myFile"; filename*=utf-8''upload_test_file_%C5%82%C3%B3%C4%85%C3%A4.txt

when accessing upload in POST handler like myFile.filename
I get file content instead of it's name.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a screenshots and logs of the problem.
import requests
fn = '/tmp/test_\xc5\x82\xc3\xb3\xc4\x85\xc3\xa4.po'
with open(fn, 'rb') as fh: r = requests.post(url, files={'myFile': fh})
  • What is the expected behavior?

I think that the best way would be to handle encoding and return name as unicode object
but if this isn't possible, perhaps return HTTP 400 Bad Request or at least throw NotImplementedError which would be returned as HTTP 500?

def POST(self, myFile):
    fname = myFile.filename  # should contain python unicode
  • What is the motivation / use case for changing the behavior?

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

https://tools.ietf.org/html/rfc5987

  • Please tell us about your environment:
  • Cheroot version: 6.0.0
  • CherryPy version: 14.0.0
  • Python version: 2.7
  • OS: linux
  • Browser: [requests ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, e.g. stackoverflow, gitter, etc.)

https://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http

pawciobiel pushed a commit to pawciobiel/cherrypy that referenced this issue Mar 1, 2018

Pawel Bielecki
* Fix _cpreqbody.Entity to handle Content-Disposition filename* with …
…encoding

* Change _cpcompat.unquote_qs to work with unicode on py2
 - fix for cherrypy#1694

pawciobiel added a commit to pawciobiel/cherrypy that referenced this issue Mar 6, 2018

* Fix _cpreqbody.Entity to handle Content-Disposition filename* with …
…encoding

* Change _cpcompat.unquote_qs to work with unicode on py2
 - fix for cherrypy#1694

pawciobiel added a commit to pawciobiel/cherrypy that referenced this issue Mar 13, 2018

* Fix _cpreqbody.Entity to handle Content-Disposition filename* with …
…encoding

* Change _cpcompat.unquote_qs to work with unicode on py2
 - fix for cherrypy#1694

@jaraco jaraco assigned jaraco and unassigned jaraco Aug 13, 2018

@webknjaz

This comment has been minimized.

Member

webknjaz commented Sep 9, 2018

Fixed by #1695

@webknjaz webknjaz closed this Sep 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment