Skip to content

Commit 54f67ad

Browse files
authored
bpo-43218: Prevent venv creation when the target directory contains a PATH separator. (pythonGH-24530)
1 parent 15537c5 commit 54f67ad

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Lib/test/test_venv.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ def test_macos_env(self):
467467
'import os; print("__PYVENV_LAUNCHER__" in os.environ)'])
468468
self.assertEqual(out.strip(), 'False'.encode())
469469

470+
def test_pathsep_error(self):
471+
"""
472+
Test that venv creation fails when the target directory contains
473+
the path separator.
474+
"""
475+
rmtree(self.env_dir)
476+
self.assertRaises(ValueError, venv.create, self.env_dir + os.pathsep)
477+
470478
@requireVenvCreate
471479
class EnsurePipTest(BaseTest):
472480
"""Test venv module installation of pip."""

Lib/venv/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def create_if_needed(d):
116116
elif os.path.islink(d) or os.path.isfile(d):
117117
raise ValueError('Unable to create directory %r' % d)
118118

119+
if os.pathsep in env_dir:
120+
raise ValueError(f'Refusing to create a venv in {env_dir} because '
121+
f'it contains the PATH separator {os.pathsep}.')
119122
if os.path.exists(env_dir) and self.clear:
120123
self.clear_directory(env_dir)
121124
context = types.SimpleNamespace()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent creation of a venv whose path contains the PATH separator. This
2+
could affect the usage of the activate script. Patch by Dustin Rodrigues.

0 commit comments

Comments
 (0)