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

urllib.request.pathname2url() and url2pathname() remove slashes on Windows #126212

Closed
barneygale opened this issue Oct 30, 2024 · 0 comments
Closed
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@barneygale
Copy link
Contributor

barneygale commented Oct 30, 2024

Bug report

Bug description:

urllib.request.pathname2url() unexpectedly removes doubled and trailing slashes, but only on Windows, and only for DOS device paths (not UNC paths):

>>> from urllib.request import pathname2url, url2pathname
>>> pathname2url('C:\\')
'///C:'  # This is *not* the same path!
>>> pathname2url('C:\\foo\\')
'///C:/foo'
>>> pathname2url('C:\\foo\\\\bar')
'///C:/foo/bar'

url2pathname() does almost the same thing, except that it specially preserves a slash immediately after a DOS drive (but not elsewhere):

>>> url2pathname('///c:/')
'C:\\'  # OK
>>> url2pathname('///c:/foo/')
'C:\\foo'
>>> url2pathname('///c:/foo//bar')
'C:\\foo\\bar'

This behaviour makes no sense and has no equivalent on POSIX, where all slashes are preserved.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

@barneygale barneygale added type-bug An unexpected behavior, bug, or error 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Oct 30, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Oct 31, 2024
Adjust `urllib.request.pathname2url()` and `url2pathname()` so that they
don't remove slashes from Windows DOS drive paths and URLs. There was no
basis for this behaviour, and it conflicts with how UNC and POSIX paths are
handled.
barneygale added a commit that referenced this issue Nov 8, 2024
Adjust `urllib.request.pathname2url()` and `url2pathname()` so that they
don't remove slashes from Windows DOS drive paths and URLs. There was no
basis for this behaviour, and it conflicts with how UNC and POSIX paths are
handled.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 8, 2024
…onGH-126214)

Adjust `urllib.request.pathname2url()` and `url2pathname()` so that they
don't remove slashes from Windows DOS drive paths and URLs. There was no
basis for this behaviour, and it conflicts with how UNC and POSIX paths are
handled.
(cherry picked from commit 54c63a3)

Co-authored-by: Barney Gale <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 8, 2024
…onGH-126214)

Adjust `urllib.request.pathname2url()` and `url2pathname()` so that they
don't remove slashes from Windows DOS drive paths and URLs. There was no
basis for this behaviour, and it conflicts with how UNC and POSIX paths are
handled.
(cherry picked from commit 54c63a3)

Co-authored-by: Barney Gale <[email protected]>
barneygale added a commit that referenced this issue Nov 8, 2024
…126214) (#126591)

GH-126212: Fix removal of slashes in file URIs on Windows (GH-126214)

Adjust `urllib.request.pathname2url()` and `url2pathname()` so that they
don't remove slashes from Windows DOS drive paths and URLs. There was no
basis for this behaviour, and it conflicts with how UNC and POSIX paths are
handled.
(cherry picked from commit 54c63a3)

Co-authored-by: Barney Gale <[email protected]>
barneygale added a commit that referenced this issue Nov 8, 2024
…126214) (#126590)

GH-126212: Fix removal of slashes in file URIs on Windows (GH-126214)

Adjust `urllib.request.pathname2url()` and `url2pathname()` so that they
don't remove slashes from Windows DOS drive paths and URLs. There was no
basis for this behaviour, and it conflicts with how UNC and POSIX paths are
handled.
(cherry picked from commit 54c63a3)

Co-authored-by: Barney Gale <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant