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

Remove leading dashes in venv names #2399

Closed
Closed
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
6 changes: 5 additions & 1 deletion pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,15 @@ def _sanitize(cls, name):
# 127 : BINPRM_BUF_SIZE - 1
# 32 : Maximum length of username
#
# Also remove leading dashes to avoid names being interpreted as
# arguments to external commands.
#
# References:
# 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]
sanitized_name = re.sub(r'[ $`!*@"\\\r\n\t]', '_', name).lstrip('-')
return sanitized_name[0:42]

def _get_virtualenv_hash(self, name):
"""Get the name of the virtualenv adjusted for windows if needed
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pipenv.project import Project

import pytest


@pytest.mark.project
def test_virtualenv_name():
project = Project()
project._name = '-directory-with-dash'
assert not project.virtualenv_name.startswith('-')