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

Conversation

tushar-balwani
Copy link

What do these changes do?

The new changes preserve casing of username and password when extracted from host in URL.build

>>> yarl.URL.build(scheme='httPS', host='usER:passWORD@hostNAME', path='/paTH')
URL('httPS://usER:passWORD@hostname/paTH')
>>> yarl.URL.build(scheme='httPS', host='usER:passWORD@hostNAME', path='/paTH').user
'usER'
>>> yarl.URL.build(scheme='httPS', host='usER:passWORD@hostNAME', path='/paTH').password
'passWORD'

Are there changes in behavior for the user?

No.

Related issue number

#880

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: Fix issue with non-ascii contents in doctest text files.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Aug 26, 2023
@@ -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?

Comment on lines +262 to +270
def test_build_with_case_sensitive_user_and_password():
url = URL.build(scheme='httPS', host='usER:passWORD@hostNAME', path='/paTH')
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"
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?

@@ -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.



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...

@webknjaz webknjaz requested a review from mjpieters November 20, 2023 00:05
@mjpieters
Copy link
Contributor

This is the wrong fix, as discussed in #880. The issue is that host should only accept a host string, not an authority string. Pass those to URL.build(authority=...) instead.

The right fix is to reject any gen-delims characters in the host value (provided it is not an IP address). Either by raising a deprecation warning first, or just going straight to raising ValueError.

@mjpieters mjpieters closed this Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants