diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-11-11 09:17:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-11 09:17:29 (GMT) |
commit | cd3e2d3a6ca4bfcc8c99eb50e92a2ce0b5b1ddf6 (patch) | |
tree | a30f876324a449671122a7c8065027d75d752b33 /Lib | |
parent | 7b55a955bc4066c5db4c842b3d7319df487fb750 (diff) | |
download | cpython-cd3e2d3a6ca4bfcc8c99eb50e92a2ce0b5b1ddf6.zip cpython-cd3e2d3a6ca4bfcc8c99eb50e92a2ce0b5b1ddf6.tar.gz cpython-cd3e2d3a6ca4bfcc8c99eb50e92a2ce0b5b1ddf6.tar.bz2 |
[3.11] gh-111841: Fix os.putenv() and os.unsetenv() with embedded NUL on Windows (GH-111842) (GH-111967)
(cherry picked from commit 0b06d2482d77e02c5d40e221f6046c9c355458b2)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_os.py | 5 | ||||
-rw-r--r-- | Lib/test/test_posix.py | 14 |
2 files changed, 11 insertions, 8 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index ff1121e..441e1f9 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1130,9 +1130,12 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): def test_putenv_unsetenv_error(self): # Empty variable name is invalid. # "=" and null character are not allowed in a variable name. - for name in ('', '=name', 'na=me', 'name=', 'name\0', 'na\0me'): + for name in ('', '=name', 'na=me', 'name='): self.assertRaises((OSError, ValueError), os.putenv, name, "value") self.assertRaises((OSError, ValueError), os.unsetenv, name) + for name in ('name\0', 'na\0me'): + self.assertRaises(ValueError, os.putenv, name, "value") + self.assertRaises(ValueError, os.unsetenv, name) if sys.platform == "win32": # On Windows, an environment variable string ("name=value" string) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 912f07e..0b1068b 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1011,20 +1011,20 @@ class PosixTester(unittest.TestCase): self.assertEqual(type(k), item_type) self.assertEqual(type(v), item_type) - @unittest.skipUnless(os.name == 'posix', "see bug gh-111841") def test_putenv(self): with self.assertRaises(ValueError): os.putenv('FRUIT\0VEGETABLE', 'cabbage') with self.assertRaises(ValueError): - os.putenv(b'FRUIT\0VEGETABLE', b'cabbage') - with self.assertRaises(ValueError): os.putenv('FRUIT', 'orange\0VEGETABLE=cabbage') with self.assertRaises(ValueError): - os.putenv(b'FRUIT', b'orange\0VEGETABLE=cabbage') - with self.assertRaises(ValueError): os.putenv('FRUIT=ORANGE', 'lemon') - with self.assertRaises(ValueError): - os.putenv(b'FRUIT=ORANGE', b'lemon') + if os.name == 'posix': + with self.assertRaises(ValueError): + os.putenv(b'FRUIT\0VEGETABLE', b'cabbage') + with self.assertRaises(ValueError): + os.putenv(b'FRUIT', b'orange\0VEGETABLE=cabbage') + with self.assertRaises(ValueError): + os.putenv(b'FRUIT=ORANGE', b'lemon') @unittest.skipUnless(hasattr(posix, 'getcwd'), 'test needs posix.getcwd()') def test_getcwd_long_pathnames(self): |