-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
PWZER
commented
Feb 22, 2019
•
edited
Loading
edited
- Suport filename length is zero for multipart/form-data.
- Recognizes non-ASCII filenames in RFC 2231 and RFC 5987, "filename*" format.
- 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 Report
@@ 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
Continue to review full report at Codecov.
|
file_name = form_parameters.get("filename") | ||
|
||
# non-ASCII filenames in RFC2231, "filename*" format | ||
if file_name is None and form_parameters.get("filename*"): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?