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

Only split headers on \n and \r\n #189

Merged
merged 2 commits into from Oct 6, 2019

Conversation

mstojcevich
Copy link

The behavior of splitlines can be problematic when used with certain characters in a unicode string:

$ python3 -c 'print("hi\x0basdf".splitlines())'
['hi', 'asdf']

During the Python 3 port, Cyclone started explicitly converting the body bytes to unicode when calling HTTPHeaders.parse, which exposes this odd behavior.

This PR changes the behavior to better match the HTTP RFCs. See the tests for more info.

@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling 34de332 on mstojcevich:cyclone-header-splitting into 4564503 on fiorix:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling 34de332 on mstojcevich:cyclone-header-splitting into 4564503 on fiorix:master.

@@ -265,7 +268,7 @@ def parse_multipart_form_data(boundary, data, arguments, files):
if eoh == -1:
log.msg("multipart/form-data missing headers")
continue
headers = HTTPHeaders.parse(part[:eoh])
headers = HTTPHeaders.parse(to_unicode(part[:eoh]))
Copy link
Author

Choose a reason for hiding this comment

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

HTTPHeaders.parse is also used in cyclone.httpserver, that usage also converts the argument to unicode first.

@fiorix fiorix merged commit fefdc51 into fiorix:master Oct 6, 2019
@fiorix
Copy link
Owner

fiorix commented Oct 6, 2019

Thanks!

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.

None yet

4 participants