bpo-30746: Prohibited the '=' character in environment variable names… · python/cpython@7770394 (original) (raw)
`@@ -2382,6 +2382,55 @@ def test_spawnve_noargs(self):
`
2382
2382
`self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], ('',), {})
`
2383
2383
`self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], [''], {})
`
2384
2384
``
``
2385
`+
@requires_os_func('spawnve')
`
``
2386
`+
def test_spawnve_invalid_env(self):
`
``
2387
`+
null character in the enviroment variable name
`
``
2388
`+
args = [sys.executable, '-c', 'pass']
`
``
2389
`+
newenv = os.environ.copy()
`
``
2390
`+
newenv["FRUIT\0VEGETABLE"] = "cabbage"
`
``
2391
`+
try:
`
``
2392
`+
exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
`
``
2393
`+
except ValueError:
`
``
2394
`+
pass
`
``
2395
`+
else:
`
``
2396
`+
self.assertEqual(exitcode, 127)
`
``
2397
+
``
2398
`+
null character in the enviroment variable value
`
``
2399
`+
args = [sys.executable, '-c', 'pass']
`
``
2400
`+
newenv = os.environ.copy()
`
``
2401
`+
newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
`
``
2402
`+
try:
`
``
2403
`+
exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
`
``
2404
`+
except ValueError:
`
``
2405
`+
pass
`
``
2406
`+
else:
`
``
2407
`+
self.assertEqual(exitcode, 127)
`
``
2408
+
``
2409
`+
equal character in the enviroment variable name
`
``
2410
`+
args = [sys.executable, '-c', 'pass']
`
``
2411
`+
newenv = os.environ.copy()
`
``
2412
`+
newenv["FRUIT=ORANGE"] = "lemon"
`
``
2413
`+
try:
`
``
2414
`+
exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
`
``
2415
`+
except ValueError:
`
``
2416
`+
pass
`
``
2417
`+
else:
`
``
2418
`+
self.assertEqual(exitcode, 127)
`
``
2419
+
``
2420
`+
equal character in the enviroment variable value
`
``
2421
`+
filename = support.TESTFN
`
``
2422
`+
self.addCleanup(support.unlink, filename)
`
``
2423
`+
with open(filename, "w") as fp:
`
``
2424
`+
fp.write('import sys, os\n'
`
``
2425
`+
'if os.getenv("FRUIT") != "orange=lemon":\n'
`
``
2426
`+
' raise AssertionError')
`
``
2427
`+
args = [sys.executable, filename]
`
``
2428
`+
newenv = os.environ.copy()
`
``
2429
`+
newenv["FRUIT"] = "orange=lemon"
`
``
2430
`+
exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
`
``
2431
`+
self.assertEqual(exitcode, 0)
`
``
2432
+
``
2433
+
2385
2434
`# The introduction of this TestCase caused at least two different errors on
`
2386
2435
`# *nix buildbots. Temporarily skip this to let the buildbots move along.
`
2387
2436
`@unittest.skip("Skip due to platform/environment differences on *NIX buildbots")
`