summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-09-15 17:19:47 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-09-15 17:19:47 (GMT)
commit8181646931fc2ae842b6c74d38f26fb1006b457e (patch)
treeedb11caeac5521257dfcf0faec88ba5ecd54586b /Lib
parent8987c9d219f0efb438f5d707a63d0a0a0f72b3ef (diff)
downloadcpython-8181646931fc2ae842b6c74d38f26fb1006b457e.zip
cpython-8181646931fc2ae842b6c74d38f26fb1006b457e.tar.gz
cpython-8181646931fc2ae842b6c74d38f26fb1006b457e.tar.bz2
Issue #28114: Fix a crash in parse_envlist() when env contains byte strings
Patch by Eryk Sun.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index d82a4a7..9096665 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2165,7 +2165,7 @@ class PidTests(unittest.TestCase):
class SpawnTests(unittest.TestCase):
- def create_args(self, with_env=False):
+ def create_args(self, with_env=False, use_bytes=False):
self.exitcode = 17
filename = support.TESTFN
@@ -2185,7 +2185,13 @@ class SpawnTests(unittest.TestCase):
with open(filename, "w") as fp:
fp.write(code)
- return [sys.executable, filename]
+ args = [sys.executable, filename]
+ if use_bytes:
+ args = [os.fsencode(a) for a in args]
+ self.env = {os.fsencode(k): os.fsencode(v)
+ for k, v in self.env.items()}
+
+ return args
@unittest.skipUnless(hasattr(os, 'spawnl'), 'need os.spawnl')
def test_spawnl(self):
@@ -2248,6 +2254,13 @@ class SpawnTests(unittest.TestCase):
else:
self.assertEqual(status, self.exitcode << 8)
+ @unittest.skipUnless(hasattr(os, 'spawnve'), 'need os.spawnve')
+ def test_spawnve_bytes(self):
+ # Test bytes handling in parse_arglist and parse_envlist (#28114)
+ args = self.create_args(with_env=True, use_bytes=True)
+ exitcode = os.spawnve(os.P_WAIT, args[0], args, self.env)
+ self.assertEqual(exitcode, self.exitcode)
+
# The introduction of this TestCase caused at least two different errors on
# *nix buildbots. Temporarily skip this to let the buildbots move along.