Skip to content

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

Closed

Description

@barneygale

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.12only security fixes
    3.13only security fixes
    3.14bugs and security fixes
    on Oct 30, 2024
  2. added a commit that references this issue on Oct 31, 2024
  3. added a commit that references this issue on Nov 8, 2024
  4. added 2 commits that reference this issue on Nov 8, 2024
  5. added 2 commits that reference this issue on Nov 8, 2024
  6. added a commit that references this issue on Dec 8, 2024
  7. added a commit that references this issue on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13only security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions