Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the case of username and password in URL.build #920

Closed
Closed
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
1 change: 1 addition & 0 deletions CHANGES/880.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve the case of username and password in URL.build when extracted from host.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use the past tense and RST markup here.

11 changes: 11 additions & 0 deletions tests/test_url_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,14 @@ def test_build_with_none_query_string():
def test_build_with_none_fragment():
with pytest.raises(TypeError):
URL.build(scheme="http", host="example.com", fragment=None)


def test_build_with_case_sensitive_user_and_password():
url = URL.build(scheme='httPS', host='usER:passWORD@hostNAME', path='/paTH')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why this information would ever be a part of the host? I don't think the API should allow for it at all...

assert url.user == "usER"
assert url.password == "passWORD"


def test_build_with_case_sensitive_user():
url = URL.build(scheme='httPS', host='usER@hostNAME', path='/paTH')
assert url.user == "usER"
Comment on lines +262 to +270
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these are the same test. So I'd recommend using @pytest.mark.parametrize to fold it.

Also, I don't believe that scheme needs to be case-insensitive. Do you have any RFC reference that clarify this corner case?

6 changes: 6 additions & 0 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ def build(
elif not user and not password and not host and not port:
netloc = ""
else:
if "@" in host and not user and not password:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a weird place to extract this data from.. Could you add more detail regarding the problem you're trying to address?

user_pass, host = host.split("@", 1)
if ":" in user_pass:
user, password = user_pass.split(":", 1)
else:
user = user_pass
netloc = cls._make_netloc(
user, password, host, port, encode=not encoded, encode_host=not encoded
)
Expand Down