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

Wrong formatting of url in urlunsplit() function when used with _replace function to change scheme #99901

Open
MKCompu opened this issue Nov 30, 2022 · 1 comment
Labels
type-bug An unexpected behavior, bug, or error

Comments

@MKCompu
Copy link

MKCompu commented Nov 30, 2022

Bug report

from urllib.parse import urlparse
malformed = urlparse("8.8.8.8:1337")._replace(scheme='http').geturl()
print(malformed)

This prints ''http:///8.8.8.8:1337", but should have printed "http://8.8.8.8:1337".
Note the three slashes.
The reason is that the urlunsplit function in Lib/urllib/parse.py checks whether the original url contains a slash, which is not the case, adds a slash and then adds two more slashes.

Your environment

  • CPython versions tested on: 3.10.5

Linked PRs

@MKCompu MKCompu added the type-bug An unexpected behavior, bug, or error label Nov 30, 2022
@WolframAlph
Copy link
Sponsor

WolframAlph commented Nov 30, 2022

urlparse("8.8.8.8:1337", scheme='http').geturl()

will also produce http:///8.8.8.8:1337
Testing with latest main.
Can I work on patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants