summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorDustin Rodrigues <dust.rod@gmail.com>2022-04-13 08:07:10 (GMT)
committerGitHub <noreply@github.com>2022-04-13 08:07:10 (GMT)
commit54f67ad54366f1b9161edca283e19670e065e1b8 (patch)
treefee5547567a1f702cd3b6187883e27163b7df22d /Lib
parent15537c51c188a6633248c25d211d5216e673aee3 (diff)
downloadcpython-54f67ad54366f1b9161edca283e19670e065e1b8.zip
cpython-54f67ad54366f1b9161edca283e19670e065e1b8.tar.gz
cpython-54f67ad54366f1b9161edca283e19670e065e1b8.tar.bz2
bpo-43218: Prevent venv creation when the target directory contains a PATH separator. (GH-24530)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_venv.py8
-rw-r--r--Lib/venv/__init__.py3
2 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index c91b754..d96cf1e 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -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."""
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index a8640d9..7bfbadd 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -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()