]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43218: Prevent venv creation when the target directory contains a PATH separator...
authorDustin Rodrigues <dust.rod@gmail.com>
Wed, 13 Apr 2022 08:07:10 +0000 (04:07 -0400)
committerGitHub <noreply@github.com>
Wed, 13 Apr 2022 08:07:10 +0000 (09:07 +0100)
Lib/test/test_venv.py
Lib/venv/__init__.py
Misc/NEWS.d/next/Library/2021-02-14-20-55-53.bpo-43218.VZv2M4.rst [new file with mode: 0644]

index c91b75493841be3a1be8c36605783354811a8075..d96cf1e6c749308f3ff5357730ffea85d014c189 100644 (file)
@@ -467,6 +467,14 @@ class BasicTest(BaseTest):
             'import os; print("__PYVENV_LAUNCHER__" in os.environ)'])
         self.assertEqual(out.strip(), 'False'.encode())
 
+    def test_pathsep_error(self):
+        """
+        Test that venv creation fails when the target directory contains
+        the path separator.
+        """
+        rmtree(self.env_dir)
+        self.assertRaises(ValueError, venv.create, self.env_dir + os.pathsep)
+
 @requireVenvCreate
 class EnsurePipTest(BaseTest):
     """Test venv module installation of pip."""
index a8640d9163fbed5f3fee9bb9c9aaa0c6b22d5539..7bfbadda7b49709f6856eaf21cc411ead8c6782b 100644 (file)
@@ -116,6 +116,9 @@ class EnvBuilder:
             elif os.path.islink(d) or os.path.isfile(d):
                 raise ValueError('Unable to create directory %r' % d)
 
+        if os.pathsep in env_dir:
+            raise ValueError(f'Refusing to create a venv in {env_dir} because '
+                             f'it contains the PATH separator {os.pathsep}.')
         if os.path.exists(env_dir) and self.clear:
             self.clear_directory(env_dir)
         context = types.SimpleNamespace()
diff --git a/Misc/NEWS.d/next/Library/2021-02-14-20-55-53.bpo-43218.VZv2M4.rst b/Misc/NEWS.d/next/Library/2021-02-14-20-55-53.bpo-43218.VZv2M4.rst
new file mode 100644 (file)
index 0000000..31229c3
--- /dev/null
@@ -0,0 +1,2 @@
+Prevent creation of a venv whose path contains the PATH separator. This
+could affect the usage of the activate script. Patch by Dustin Rodrigues.