Skip to content

Commit 643217b

Browse files
authored
Merge pull request #9207 from NoahGorny/fix-redact-url-from-help
2 parents 7c00e6f + 8de94b5 commit 643217b

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

news/9191.bugfix.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix crash when logic for redacting authentication information from URLs
2+
in ``--help`` is given a list of strings, instead of a single string.

src/pip/_internal/cli/parser.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,23 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
112112
"""
113113

114114
def expand_default(self, option):
115-
default_value = None
115+
default_values = None
116116
if self.parser is not None:
117117
self.parser._update_defaults(self.parser.defaults)
118-
default_value = self.parser.defaults.get(option.dest)
118+
default_values = self.parser.defaults.get(option.dest)
119119
help_text = optparse.IndentedHelpFormatter.expand_default(self, option)
120120

121-
if default_value and option.metavar == 'URL':
122-
help_text = help_text.replace(
123-
default_value, redact_auth_from_url(default_value))
121+
if default_values and option.metavar == 'URL':
122+
if isinstance(default_values, string_types):
123+
default_values = [default_values]
124+
125+
# If its not a list, we should abort and just return the help text
126+
if not isinstance(default_values, list):
127+
default_values = []
128+
129+
for val in default_values:
130+
help_text = help_text.replace(
131+
val, redact_auth_from_url(val))
124132

125133
return help_text
126134

tests/functional/test_help.py

+11
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ def test_help_command_redact_auth_from_url(script):
7474
assert 'secret' not in result.stdout
7575

7676

77+
def test_help_command_redact_auth_from_url_with_extra_index_url(script):
78+
"""
79+
Test `help` on various subcommands redact auth from url with extra index url
80+
"""
81+
script.environ['PIP_INDEX_URL'] = 'https://user:[email protected]'
82+
script.environ['PIP_EXTRA_INDEX_URL'] = 'https://user:[email protected]'
83+
result = script.pip('install', '--help')
84+
assert result.returncode == SUCCESS
85+
assert 'secret' not in result.stdout
86+
87+
7788
def test_help_commands_equally_functional(in_memory_pip):
7889
"""
7990
Test if `pip help` and 'pip --help' behave the same way.

0 commit comments

Comments
 (0)