8000 bpo-44647: Fix test_httpservers failing on Unicode characters in os.environ on Windows by ambv · Pull Request #27161 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44647: Fix test_httpservers failing on Unicode characters in os.environ on Windows #27161

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

Merged
merged 7 commits into from
Jul 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix test for unaccounted for Unicode characters in environment
  • Loading branch information
ambv committed Jul 15, 2021
commit 197f9bdf0ef1968e1c3c326b0244182ef229a3af
15 changes: 9 additions & 6 deletions Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,13 @@ def test_html_escape_filename(self):
print("Content-type: text/html")
print()
print("<pre>")
print(repr(os.environ))
for k, v in os.environ.items():
try:
k.encode('ascii')
v.encode('ascii')
except UnicodeEncodeError:
continue # see: BPO-44647
print(f"{k}={v}")
print("</pre>")
"""

Expand Down Expand Up @@ -848,16 +854,13 @@ def test_accept(self):
((('Accept', 'text/html'), ('ACCEPT', 'text/plain')),
'text/html,text/plain'),
)
count = 0
for headers, expected in tests:
count += 1
headers = OrderedDict(headers)
with self.subTest(headers):
res = self.request('/cgi-bin/file6.py', 'GET', headers=headers)
self.assertEqual(http.HTTPStatus.OK, res.status)
print(count, self.HOST, self.PORT, res.length, res.status, repr(str(res.headers)), dict(os.environ))
expected = f"'HTTP_ACCEPT': {expected!r}"
self.assertIn(expected.encode('ascii'), res.read())
expected = f"HTTP_ACCEPT={expected}".encode('ascii')
self.assertIn(expected, res.read())


class SocketlessRequestHandler(SimpleHTTPRequestHandler):
Expand Down
0