summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorƁukasz Langa <lukasz@langa.pl>2021-07-15 19:14:24 (GMT)
committerGitHub <noreply@github.com>2021-07-15 19:14:24 (GMT)
commit82b218f36ce6ef910bda5af227a9fd5be613c94f (patch)
tree29ee7df4d591459f46fab22631c22d6992a9ad59
parenta86f7dae0acf918d54086cb85e5a0b0bedeedce7 (diff)
downloadcpython-82b218f36ce6ef910bda5af227a9fd5be613c94f.zip
cpython-82b218f36ce6ef910bda5af227a9fd5be613c94f.tar.gz
cpython-82b218f36ce6ef910bda5af227a9fd5be613c94f.tar.bz2
bpo-44647: Fix test_httpservers failing on Unicode characters in os.environ on Windows (GH-27161)
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.
-rw-r--r--Lib/test/test_httpservers.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index aeea020..69790ec 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -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):