venv: '!' in --prompt breaks activate.csh (csh history expansion)
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Bug report
venv quotes substituted strings in its activation scripts with POSIX
shlex.quote() for every script except .ps1/.bat (gh-124651). That is
wrong for activate.csh: (t)csh performs history expansion on ! even
inside single quotes, so a --prompt (or path) containing ! followed by a
word character produces an activate.csh that fails to source.
Reproducer
$ python -m venv --prompt 'py!env' /tmp/env
$ csh -c 'source /tmp/env/bin/activate.csh'
env: Event not found.
activate.csh runs setenv VIRTUAL_ENV_PROMPT 'py!env'; csh history-expands
!env, the line errors, and activation aborts (VIRTUAL_ENV/prompt unset).
Both csh and tcsh are affected; bash/zsh activate and activate.fish
are not (POSIX-compatible single quotes).
Cause
Lib/venv/__init__.py:replace_variables() dispatches the quoting function by
script suffix (.ps1 -> quote_ps1, .bat -> quote_bat, else -> shlex.quote).
activate.csh falls into the POSIX branch, which does not account for csh
history expansion.
Scope
--prompt is the cleanest case: the venv path is clean, so source works and
only the substituted prompt breaks -- fully fixable in venv. A ! in the venv
directory path is also mis-quoted by venv internally (same root cause), but
note that activating such a venv additionally requires the user to escape the
! in their own source <path> command line, which is outside venv's control.
Fix
Add a quote_csh that escapes !, and dispatch on .csh -- mirroring the
existing quote_ps1/quote_bat handling. Verified under csh and tcsh:
!, quotes, $, backtick, ;, &&, spaces, parens round-trip. (A newline
cannot be represented in a csh single-quoted string; that remains out of scope
and is unchanged from current behavior.)
Not a security issue: csh errors out rather than executing anything.
Linked PRs
- gh-152687
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans Lib/venv/init.py, au niveau de replace_variables(), et comparez son dispatch existant entre quote_ps1 et quote_bat. Reproduisez l’échec avec un --prompt contenant !, puis faites source du activate.csh généré sous csh et tcsh. C’est terminé lorsque le prompt et les autres caractères spéciaux listés effectuent un aller-retour sans que l’activation échoue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python, shell
- Domaine
- cli, tooling
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 35/100