Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-148315: Shell-quote the command line in pyvenv.cfg
The `command = ...` record written to `pyvenv.cfg` by
`venv.EnvBuilder.create_configuration` was assembled with a plain
`' '.join(args)` and an unquoted `sys.executable`. When any of these
tokens contained whitespace (for example a Windows user directory like
`C:\Users\Z B\...`), the recorded command was no longer a faithful
reproduction and truncated at the first space when shell-parsed.

Build the full argv as a list and emit it via `shlex.join`, and split
`--prompt="..."` into two separate argv tokens so its value is quoted
by `shlex.join` as well.
  • Loading branch information
pratyush618 committed Apr 11, 2026
commit 837a42db0c8f99dcd29562071010f1955f4fce14
9 changes: 6 additions & 3 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,16 @@ def create_configuration(self, context):
if self.upgrade_deps:
args.append('--upgrade-deps')
if self.orig_prompt is not None:
args.append(f'--prompt="{self.orig_prompt}"')
args.extend(['--prompt', self.orig_prompt])
if not self.scm_ignore_files:
args.append('--without-scm-ignore-files')

args.append(context.env_dir)
args = ' '.join(args)
f.write(f'command = {sys.executable} -m venv {args}\n')
# gh-148315: shell-quote so paths containing whitespace
# (e.g. a Windows user directory with a space) round-trip
# faithfully and the recorded command can be re-executed.
command = shlex.join([sys.executable, '-m', 'venv', *args])
f.write(f'command = {command}\n')

def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):
"""
Expand Down