Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed as not planned
@MKCompu

Description

@MKCompu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions