Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions httpie/cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from argparse import RawDescriptionHelpFormatter
from textwrap import dedent
from urllib.parse import urlsplit
from urllib.parse import unquote

from requests.utils import get_netrc_auth

Expand Down Expand Up @@ -289,8 +290,8 @@ def _process_auth(self):
if self.args.auth is None and not auth_type_set:
if url.username is not None:
# Handle http://username:password@hostname/
username = url.username
password = url.password or ''
username = unquote(url.username) if url.username else None
password = unquote(url.password) if url.password else ''
self.args.auth = AuthCredentials(
key=username,
value=password,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,11 @@ def test_ignore_netrc_null_auth():
env=MockEnvironment(),
)
assert isinstance(args.auth, ExplicitNullAuth)

def test_percent_encoded_credentials_in_url(httpbin_both):
encoded_url = httpbin_both.url.replace("://", "://u%40d:1%3d2%3f@") + '/basic-auth/u%40d/1%3d2%3f'

r = http('GET', encoded_url)

assert HTTP_OK in r
assert r.json == {'authenticated': True, 'user': 'u@d'}
2 changes: 1 addition & 1 deletion tests/test_cli_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

NAKED_HELP_MESSAGE_PRETTY_WITH_INVALID_ARG = NAKED_BASE_TEMPLATE.format(
extra_args="--pretty {all, colors, format, none} ",
error_msg="argument --pretty: invalid choice: '$invalid' (choose from 'all', 'colors', 'format', 'none')"
error_msg="argument --pretty: invalid choice: '$invalid' (choose from all, colors, format, none)"
)


Expand Down
Loading