From cf0f79bb1795001fdf12b7031131ed1e7912c209 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Wed, 8 Dec 2021 18:44:11 +0000 Subject: [PATCH] Improve how editors are handled in `pip config` --- src/pip/_internal/commands/configuration.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/commands/configuration.py b/src/pip/_internal/commands/configuration.py index c6c74ed50ba..a9afb7342d4 100644 --- a/src/pip/_internal/commands/configuration.py +++ b/src/pip/_internal/commands/configuration.py @@ -222,9 +222,13 @@ def open_in_editor(self, options: Values, args: List[str]) -> None: fname = self.configuration.get_file_to_edit() if fname is None: raise PipError("Could not determine appropriate file.") + elif '"' in fname: + # This shouldn't happen, unless we see a username like that. + # If that happens, we'd appreciate a pull request fixing this. + raise PipError('Can not open an editor for a file name containing ".') try: - subprocess.check_call([editor, fname]) + subprocess.check_call(f'{editor} "{fname}"', shell=True) except subprocess.CalledProcessError as e: raise PipError( "Editor Subprocess exited with exit code {}".format(e.returncode)