diff options
author | Pradyun Gedam <3275593+pradyunsg@users.noreply.github.com> | 2020-12-08 12:56:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 12:56:00 +0000 |
commit | 643217bc35cbd26e24ac5e35466f8b7d7d0ed9fb (patch) | |
tree | 2a7b2fe1f1b37f46b87d6520a4235bebae53dcc6 | |
parent | 7c00e6f3fd418975a57a0da180c454bc1f629569 (diff) | |
parent | 8de94b5740ac0fb83f3dc899c9d4f23d85ed82c0 (diff) | |
download | pip-643217bc35cbd26e24ac5e35466f8b7d7d0ed9fb.tar.gz |
Merge pull request #9207 from NoahGorny/fix-redact-url-from-help
-rw-r--r-- | news/9191.bugfix.rst | 2 | ||||
-rw-r--r-- | src/pip/_internal/cli/parser.py | 18 | ||||
-rw-r--r-- | tests/functional/test_help.py | 11 |
3 files changed, 26 insertions, 5 deletions
diff --git a/news/9191.bugfix.rst b/news/9191.bugfix.rst new file mode 100644 index 000000000..e1c6d633d --- /dev/null +++ b/news/9191.bugfix.rst @@ -0,0 +1,2 @@ +Fix crash when logic for redacting authentication information from URLs +in ``--help`` is given a list of strings, instead of a single string. diff --git a/src/pip/_internal/cli/parser.py b/src/pip/_internal/cli/parser.py index ea3b383e2..7170bfd38 100644 --- a/src/pip/_internal/cli/parser.py +++ b/src/pip/_internal/cli/parser.py @@ -112,15 +112,23 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter): """ def expand_default(self, option): - default_value = None + default_values = None if self.parser is not None: self.parser._update_defaults(self.parser.defaults) - default_value = self.parser.defaults.get(option.dest) + default_values = self.parser.defaults.get(option.dest) help_text = optparse.IndentedHelpFormatter.expand_default(self, option) - if default_value and option.metavar == 'URL': - help_text = help_text.replace( - default_value, redact_auth_from_url(default_value)) + if default_values and option.metavar == 'URL': + if isinstance(default_values, string_types): + default_values = [default_values] + + # If its not a list, we should abort and just return the help text + if not isinstance(default_values, list): + default_values = [] + + for val in default_values: + help_text = help_text.replace( + val, redact_auth_from_url(val)) return help_text diff --git a/tests/functional/test_help.py b/tests/functional/test_help.py index 9c2508abb..a660cdf52 100644 --- a/tests/functional/test_help.py +++ b/tests/functional/test_help.py @@ -74,6 +74,17 @@ def test_help_command_redact_auth_from_url(script): assert 'secret' not in result.stdout +def test_help_command_redact_auth_from_url_with_extra_index_url(script): + """ + Test `help` on various subcommands redact auth from url with extra index url + """ + script.environ['PIP_INDEX_URL'] = 'https://user:secret@example.com' + script.environ['PIP_EXTRA_INDEX_URL'] = 'https://user:secret@example2.com' + result = script.pip('install', '--help') + assert result.returncode == SUCCESS + assert 'secret' not in result.stdout + + def test_help_commands_equally_functional(in_memory_pip): """ Test if `pip help` and 'pip --help' behave the same way. |