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
6 changes: 3 additions & 3 deletions httpie/cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from argparse import RawDescriptionHelpFormatter
from textwrap import dedent
from urllib.parse import urlsplit
from urllib.parse import urlsplit, unquote

from requests.utils import get_netrc_auth

Expand Down Expand Up @@ -289,8 +289,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)
password = unquote(url.password) if url.password else ''
self.args.auth = AuthCredentials(
key=username,
value=password,
Expand Down
21 changes: 21 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ def test_credentials_in_url_auth_flag_has_priority(httpbin_both):
assert r.json == {'authenticated': True, 'user': 'user'}


@pytest.mark.parametrize('url, expected_username, expected_password', [
# %40 = @, %3d = =, %3f = ?
('u%40d:1%3d2%[email protected]', 'u@d', '1=2?'),
# %3A = :
('user%3Aname:pass%[email protected]', 'user:name', 'pass:word'),
# Simple case without encoding
('user:[email protected]', 'user', 'password'),
])
def test_percent_encoded_credentials_in_url(url, expected_username, expected_password):
"""
Percent-encoded characters in URL credentials should be decoded.

https://github.com/httpie/cli/issues/1623

"""
args = httpie.cli.definition.parser.parse_args(args=[url], env=MockEnvironment())
assert args.auth
assert args.auth.username == expected_username
assert args.auth.password == expected_password


@pytest.mark.parametrize('url', [
'[email protected]',
'username:@example.org',
Expand Down
Loading