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

Recognizes non-ASCII filenames in RFC 2231, and suport filename length is zero for multipart/form-data. #1497

Merged
merged 3 commits into from
Feb 28, 2019

Conversation

PWZER
Copy link
Contributor

@PWZER PWZER commented Feb 22, 2019

  • Suport filename length is zero for multipart/form-data.
    ------sanic
    Content-Disposition: form-data; filename=""; name="test"
    
    ok
    
    ------sanic--
    
  • Recognizes non-ASCII filenames in RFC 2231 and RFC 5987, "filename*" format.
    ------sanic
    Content-Disposition: form-data; filename*="utf-8''filename_%C2%A0_test"; name="test"
    
    ok
    
    ------sanic--
    
  • Add some test cases in tests/test_requests.py::test_request_multipart_files, like those above.

2. Now recognizes non-ASCII filenames in RFC 2231, "filename*" format
3. Add some test cases in tests/test_requests.py::test_request_multipart_files.
@codecov
Copy link

codecov bot commented Feb 22, 2019

Codecov Report

Merging #1497 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1497      +/-   ##
==========================================
- Coverage   91.45%   91.41%   -0.04%     
==========================================
  Files          17       17              
  Lines        1731     1735       +4     
  Branches      330      331       +1     
==========================================
+ Hits         1583     1586       +3     
  Misses        123      123              
- Partials       25       26       +1
Impacted Files Coverage Δ
sanic/request.py 99.52% <100%> (ø) ⬆️
sanic/router.py 95.43% <0%> (-0.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52deeba...7b0214d. Read the comment docs.

file_name = form_parameters.get("filename")

# non-ASCII filenames in RFC2231, "filename*" format
if file_name is None and form_parameters.get("filename*"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the form_parameters lookup is being done twice, maybe we can move the lookup to a single line and use a variable instead? (this is just a good to have change)

filename_rfc5987 = form_parameters.get("filename*")

if not file_name and filename_rfc5987:
    encoding, _, value = email.utils.decode_rfc5987(filename_rfc2231)
    file_name = unquote(value, encoding=encoding)

Also the format you are using is RFC 5987 standard and not RFC2231 if I remember correctly. (Sorry, for the nitpicking)

elif form_header_field == "content-type":
content_type = form_header_value
content_charset = form_parameters.get("charset", "utf-8")

if field_name:
post_data = form_part[line_index:-4]
if file_name:
if file_name is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be changed to if not file_name? Also, is there a reason to switch and invert the existing check here?

@sjsadowski sjsadowski merged commit 8a59907 into sanic-org:master Feb 28, 2019
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

Successfully merging this pull request may close these issues.

4 participants