Repository navigation
🐛 fix(activation): stop bash re-expanding the prompt in PS1 - #3326
Merged
Merged
Conversation
gaborbernat
force-pushed
the
fix/bash-prompt-expansion
branch
from
September 26, 2026 16:12
e83f9af to
4f9c756
Compare
Bash re-runs parameter, command and arithmetic expansion on PS1 each time it draws the prompt, so an environment name or --prompt holding $(...), backticks or backslashes ran as a command on every prompt. Escape those characters when building PS1. The escaping uses bash-only substitution, so it runs only under bash: dash rejects the syntax and would abort the whole activation, and zsh does not expand PS1 without PROMPT_SUBST.
gaborbernat
force-pushed
the
fix/bash-prompt-expansion
branch
from
September 26, 2026 16:23
4f9c756 to
12d6f80
Compare
gaborbernat
added a commit
that referenced
this pull request
Oct 12, 2026
bash handles `PS1` in two passes each time it draws the prompt: it first decodes backslash prompt escapes, turning `\\` into `\` and `\$` into `$` (or `#` for root), and then expands the result. The bash `activate` script escaped the environment name for the expansion pass only (#3326), so a backslash in the name undoes that escaping. 🔐 A name such as `a\$(touch PWNED)`, from the directory, `--prompt` or `VIRTUALENV_PROMPT`, runs the command each time bash draws the prompt. For root, `\$` decodes to `#`, so the same name renders wrong but runs nothing. Under bash, `activate` now escapes backslashes, dollar signs and backticks a second time, so both passes leave the name literal. zsh does no decode pass, so it keeps the single escaping added in 5b91536. The prompt tests gain cases for a backslash before `$(...)` and before backticks, and for names with a backslash before `$`, before a backtick, doubled, and trailing; they render through bash 5.2 and zsh 5.9 and pass as root and as an unprivileged user. Every release up to 21.14.6 is affected, and earlier releases before 21.13.0 do not escape the name at all.
Merged
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bash re-expands
PS1every time it draws the prompt, so a venv whose name or--promptholds$(...)or backticks ran that command on each prompt after activation; this reproduces with bash 5.3. 🐛activate.shnow escapes\,$and backticks before putting the prompt intoPS1. The escaping runs under bash only: dash rejects the syntax and would abort activation, and zsh does not expandPS1by default. A new test sources the script under dash.