mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	bpo-30746: Prohibited the '=' character in environment variable names (#2382)
in `os.putenv()` and `os.spawn*()`.
This commit is contained in:
		
							parent
							
								
									1ba9469e9f
								
							
						
					
					
						commit
						77703942c5
					
				
					 4 changed files with 95 additions and 4 deletions
				
			
		|  | @ -2382,6 +2382,55 @@ def test_spawnve_noargs(self): | |||
|         self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], ('',), {}) | ||||
|         self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], [''], {}) | ||||
| 
 | ||||
|     @requires_os_func('spawnve') | ||||
|     def test_spawnve_invalid_env(self): | ||||
|         # null character in the enviroment variable name | ||||
|         args = [sys.executable, '-c', 'pass'] | ||||
|         newenv = os.environ.copy() | ||||
|         newenv["FRUIT\0VEGETABLE"] = "cabbage" | ||||
|         try: | ||||
|             exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv) | ||||
|         except ValueError: | ||||
|             pass | ||||
|         else: | ||||
|             self.assertEqual(exitcode, 127) | ||||
| 
 | ||||
|         # null character in the enviroment variable value | ||||
|         args = [sys.executable, '-c', 'pass'] | ||||
|         newenv = os.environ.copy() | ||||
|         newenv["FRUIT"] = "orange\0VEGETABLE=cabbage" | ||||
|         try: | ||||
|             exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv) | ||||
|         except ValueError: | ||||
|             pass | ||||
|         else: | ||||
|             self.assertEqual(exitcode, 127) | ||||
| 
 | ||||
|         # equal character in the enviroment variable name | ||||
|         args = [sys.executable, '-c', 'pass'] | ||||
|         newenv = os.environ.copy() | ||||
|         newenv["FRUIT=ORANGE"] = "lemon" | ||||
|         try: | ||||
|             exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv) | ||||
|         except ValueError: | ||||
|             pass | ||||
|         else: | ||||
|             self.assertEqual(exitcode, 127) | ||||
| 
 | ||||
|         # equal character in the enviroment variable value | ||||
|         filename = support.TESTFN | ||||
|         self.addCleanup(support.unlink, filename) | ||||
|         with open(filename, "w") as fp: | ||||
|             fp.write('import sys, os\n' | ||||
|                      'if os.getenv("FRUIT") != "orange=lemon":\n' | ||||
|                      '    raise AssertionError') | ||||
|         args = [sys.executable, filename] | ||||
|         newenv = os.environ.copy() | ||||
|         newenv["FRUIT"] = "orange=lemon" | ||||
|         exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv) | ||||
|         self.assertEqual(exitcode, 0) | ||||
| 
 | ||||
| 
 | ||||
| # The introduction of this TestCase caused at least two different errors on | ||||
| # *nix buildbots. Temporarily skip this to let the buildbots move along. | ||||
| @unittest.skip("Skip due to platform/environment differences on *NIX buildbots") | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka