mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
bpo-44647: Fix test_httpservers failing on Unicode characters in os.environ on Windows (GH-27161) (#27169)
GH-23638 introduced a new test for Accept: headers in CGI HTTP servers. This test serializes all of os.environ on the server side. For non-UTF8 locales this can fail for some Unicode characters found in environment variables. This change fixes the HTTP_ACCEPT test.
(cherry picked from commit 82b218f36c
)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
47695e3c88
commit
356bdff1e9
1 changed files with 13 additions and 4 deletions
|
@ -593,9 +593,18 @@ cgi_file6 = """\
|
|||
#!%s
|
||||
import os
|
||||
|
||||
print("Content-type: text/plain")
|
||||
print("X-ambv: was here")
|
||||
print("Content-type: text/html")
|
||||
print()
|
||||
print(repr(os.environ))
|
||||
print("<pre>")
|
||||
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>")
|
||||
"""
|
||||
|
||||
|
||||
|
@ -850,8 +859,8 @@ class CGIHTTPServerTestCase(BaseTestCase):
|
|||
with self.subTest(headers):
|
||||
res = self.request('/cgi-bin/file6.py', 'GET', headers=headers)
|
||||
self.assertEqual(http.HTTPStatus.OK, res.status)
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue