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

URL.with_port() reencoding user/password #620

Closed
1 task done
elciok opened this issue Sep 24, 2021 · 1 comment · Fixed by #623
Closed
1 task done

URL.with_port() reencoding user/password #620

elciok opened this issue Sep 24, 2021 · 1 comment · Fixed by #623

Comments

@elciok
Copy link
Contributor

elciok commented Sep 24, 2021

Describe the bug

When an URL already contains user and password, calling URL.to_path() is replacing special characters for strings that were already encoded.

To Reproduce

The second assert in the following snippet fails, but it should pass:

from yarl import URL

assert (
    str(URL("http://user%name:pass%word@localhost/"))
    == "http://user%25name:pass%25word@localhost/"
)
assert (
    str(URL("http://user%name:pass%word@localhost/").with_port(9000))
    == "http://user%25name:pass%25word@localhost:9000/"
)

Expected behavior

A URL user/password like "user%name" should be encoded as "user%25name", but calling to_path changes it to "user%2525name".

Logs/tracebacks

Traceback (most recent call last):
  File "/tmp/yarltesting.py", line 7, in <module>
    assert (
AssertionError

Python Version

$ python --version

Python 3.9.6

multidict Version

$ python -m pip show multidict

Name: multidict
Version: 5.1.0
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /home/elciok/.cache/pypoetry/virtualenvs/archiver-6vV8vJQs-py3.9/lib/python3.9/site-packages
Requires: 
Required-by: yarl

yarl Version

$ python -m pip show yarl

Name: yarl
Version: 1.6.3
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /home/elciok/.cache/pypoetry/virtualenvs/archiver-6vV8vJQs-py3.9/lib/python3.9/site-packages
Requires: idna, multidict

OS

$ lsb_release -a

LSB Version: core-9.20170808ubuntu1-noarch:printing-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@elciok elciok added the bug label Sep 24, 2021
@asvetlov
Copy link
Member

asvetlov commented Oct 5, 2021

We need a champion for the bug. Please feel free to create a Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants