Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4538 - Improve virtualenv path sanitazation to allow for activation #4540

Merged
merged 3 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions news/4538.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where environment wouldn't activate in paths containing & and $ symbols
2 changes: 1 addition & 1 deletion pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def _sanitize(cls, name):
# https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
# http://www.tldp.org/LDP/abs/html/special-chars.html#FIELDREF
# https://github.com/torvalds/linux/blob/2bfe01ef/include/uapi/linux/binfmts.h#L18
return re.sub(r'[ $`!*@"\\\r\n\t]', "_", name)[0:42]
return re.sub(r'[ &$`!*@"\\\r\n\t]', "_", name)[0:42]

def _get_virtualenv_hash(self, name):
# type: (str) -> str
Expand Down
5 changes: 3 additions & 2 deletions pipenv/shells.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import contextlib
import os
import re
import signal
import subprocess
import sys
Expand Down Expand Up @@ -47,9 +48,9 @@ def _get_activate_script(cmd, venv):
else:
suffix = ""
command = "."
# Escape any spaces located within the virtualenv path to allow
# Escape any special characters located within the virtualenv path to allow
# for proper activation.
venv_location = str(venv).replace(" ", r"\ ")
venv_location = re.sub(r'([ &$])', r"\\\1", str(venv))
# The leading space can make history cleaner in some shells.
return " {2} {0}/bin/activate{1}".format(venv_location, suffix, command)

Expand Down