-
Notifications
You must be signed in to change notification settings - Fork 110
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
WebTest not handling non-ascii HTTP headers correctly in Python 2.7 #186
Comments
HTTP headers are ASCII and may not include UTF-8. You'll need to percent encode the file name before sending it out. The HTTP protocol does not allow for non-ASCII characters: |
Ok, I see. Should WebTest remove the support for latin1 HTTP headers then? The reason I am raising this issue is because the test would probably pass if it was Python 3. |
From PEP3333:
|
In this commit 7d539b6, in particular this change: -def _assert_latin1_py3(string, message):
- if PY3 and type(string) is str:
- try:
- string.encode('latin1')
- except UnicodeEncodeError:
- raise AssertionError(message)
+def _assert_latin1_str(string, message):
+ assert type(string) is str, message
+ try:
+ string.encode('latin1')
+ except UnicodeEncodeError:
+ raise AssertionError(message) The above does not work for Python2. The reason is because Python2 To demonstrate the difference:
|
The linter should probably catch that the header contains invalid characters. https://tools.ietf.org/html/rfc6266#section-4.3 For encoding the filename if you are using non https://tools.ietf.org/html/rfc5987 I will note that even though the RFC's talk about https://tools.ietf.org/html/rfc7230#section-3.2.4 says:
The webtest linter could probably do a better job at that, and in the future I may add similar checks when setting headers to WebOb so that invalid data is not allowed to be returned to an unsuspecting client. |
I understand what you're saying there. You might want more discussion about whether the linter should accept non ascii headers in the future. What I am hoping for in this issue is for Python2 and Python3 to give the same result. |
In one of our tests, we are returning
attached; filename=useful-inførmation-5.pdf
in the HTTP headers. This is the traceback:The text was updated successfully, but these errors were encountered: