File tree 3 files changed +26
-5
lines changed
3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change @@ -112,15 +112,23 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
112
112
"""
113
113
114
114
def expand_default (self , option ):
115
- default_value = None
115
+ default_values = None
116
116
if self .parser is not None :
117
117
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 )
119
119
help_text = optparse .IndentedHelpFormatter .expand_default (self , option )
120
120
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 ))
124
132
125
133
return help_text
126
134
Original file line number Diff line number Diff line change @@ -74,6 +74,17 @@ def test_help_command_redact_auth_from_url(script):
74
74
assert 'secret' not in result .stdout
75
75
76
76
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
+
77
88
def test_help_commands_equally_functional (in_memory_pip ):
78
89
"""
79
90
Test if `pip help` and 'pip --help' behave the same way.
You can’t perform that action at this time.
0 commit comments