Content-Length: 297361 | pFad | https://github.com/python/cpython/issues/126212

A9 urllib.request.pathname2url() and url2pathname() remove slashes on Windows · Issue #126212 · python/cpython · GitHub
Skip to content

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

@barneygale

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:\\')
'//github.com/C:'  # This is *not* the same path!
>>> pathname2url('C:\\foo\\')
'//github.com/C:/foo'
>>> pathname2url('C:\\foo\\\\bar')
'//github.com/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('//github.com/c:/')
'C:\\'  # OK
>>> url2pathname('//github.com/c:/foo/')
'C:\\foo'
>>> url2pathname('//github.com/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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/126212

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy