From f2092131967ff34eb37425bfc2c7674941741ed7 Mon Sep 17 00:00:00 2001 From: Josh Stern Date: Mon, 29 Jul 2024 17:36:09 -0400 Subject: [PATCH 1/3] Check end of path for shell detection Addresses issue: #6197 Previously these branches would trip if the shell name was present anywhere in the cmd path. This updates the check to only look at the end. --- news/6197.bugfix.rst | 1 + pipenv/shells.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 news/6197.bugfix.rst diff --git a/news/6197.bugfix.rst b/news/6197.bugfix.rst new file mode 100644 index 0000000000..bf28c7e0a1 --- /dev/null +++ b/news/6197.bugfix.rst @@ -0,0 +1 @@ +Update shell detection to only check the end of the command used. diff --git a/pipenv/shells.py b/pipenv/shells.py index 89467cddb8..00e8358ad9 100644 --- a/pipenv/shells.py +++ b/pipenv/shells.py @@ -37,17 +37,17 @@ def _get_activate_script(cmd, venv): """ # Suffix and source command for other shells. # Support for fish shell. - if "fish" in cmd: + if cmd.endswith("fish"): suffix = ".fish" command = "source" # Support for csh shell. - elif "csh" in cmd: + elif cmd.endswith("csh"): suffix = ".csh" command = "source" - elif "xonsh" in cmd: + elif cmd.endswith("xonsh"): suffix = ".xsh" command = "source" - elif "nu" in cmd: + elif cmd.endswith("nu"): suffix = ".nu" command = "overlay use" else: From 42291476ec7092a3e27ec6eee2c654c4b1644f52 Mon Sep 17 00:00:00 2001 From: Josh Stern Date: Tue, 30 Jul 2024 16:37:14 -0400 Subject: [PATCH 2/3] Add slash to cmd check --- pipenv/shells.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pipenv/shells.py b/pipenv/shells.py index 00e8358ad9..34d3f2d0b3 100644 --- a/pipenv/shells.py +++ b/pipenv/shells.py @@ -37,17 +37,17 @@ def _get_activate_script(cmd, venv): """ # Suffix and source command for other shells. # Support for fish shell. - if cmd.endswith("fish"): + if cmd.endswith("/fish"): suffix = ".fish" command = "source" # Support for csh shell. - elif cmd.endswith("csh"): + elif cmd.endswith("/csh"): suffix = ".csh" command = "source" - elif cmd.endswith("xonsh"): + elif cmd.endswith("/xonsh"): suffix = ".xsh" command = "source" - elif cmd.endswith("nu"): + elif cmd.endswith("/nu"): suffix = ".nu" command = "overlay use" else: From f5eb9230e30fef5d9dc5ead84f0accc3585a29e5 Mon Sep 17 00:00:00 2001 From: Josh Stern Date: Tue, 30 Jul 2024 17:47:31 -0400 Subject: [PATCH 3/3] Add strict set of allowed shells Updates the if else block to only allow an explicit set of shells instead of defaulting to the `activate` script. --- pipenv/shells.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pipenv/shells.py b/pipenv/shells.py index 34d3f2d0b3..634e39088b 100644 --- a/pipenv/shells.py +++ b/pipenv/shells.py @@ -37,7 +37,10 @@ def _get_activate_script(cmd, venv): """ # Suffix and source command for other shells. # Support for fish shell. - if cmd.endswith("/fish"): + if cmd.endswith("/sh", "/bash", "/zsh"): + suffix = "" + command = "." + elif cmd.endswith("/fish"): suffix = ".fish" command = "source" # Support for csh shell. @@ -51,8 +54,7 @@ def _get_activate_script(cmd, venv): suffix = ".nu" command = "overlay use" else: - suffix = "" - command = "." + raise ValueError(f"unknown shell {cmd}") # Escape any special characters located within the virtualenv path to allow # for proper activation. venv_location = re.sub(r"([ &$()\[\]])", r"\\\1", str(venv))