Skip to content

urllib.request.url2pathname() mishandles empty authority sections (mostly) #126766

Closed

Description

@barneygale

Bug report

Bug description:

File URIs that start with 3+ slashes should be parsed as having an empty authority section (ref), but urllib.request.url2pathname() incorrectly retains the slashes introducing the authority section. This means it can't properly parse the most common form of POSIX absolute file URIs (e.g. file:///etc/hosts).

On Windows, url2pathname() correctly discards slashes before DOS drives (so file:///c:/foo is parsed as c:\foo), and before old-fashioned UNC URIs (so file:////server/share is parsed as \\server\share), but incorrectly retains slashes if a rooted, driveless path is decoded (so file:///foo/bar is decoded as \\\foo\bar instead of \foo\bar). This is much less of a problem because such paths are rare on Windows.

>>> from urllib.request import url2pathname
>>> url2pathname('///etc/hosts')
'///etc/hosts'  # expected: '/etc/hosts'

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux, Windows

Linked PRs

Activity

  1. added a commit that references this issue on Nov 12, 2024
  2. added
    3.12only security fixes
    3.13only security fixes
    3.14bugs and security fixes
    on Nov 13, 2024
  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 14, 2024
  4. added a commit that references this issue on Nov 14, 2024
  5. added 2 commits that reference this issue on Nov 14, 2024
  6. added 2 commits that reference this issue on Nov 14, 2024
  7. barneygale commented on Nov 22, 2024

    @barneygale
    ContributorAuthor

    Re-opening: we should handle 'localhost' authorities in exactly the same way.

  8. added 2 commits that reference this issue on Nov 22, 2024
  9. added 2 commits that reference this issue on Nov 22, 2024
  10. added 2 commits that reference this issue on Nov 22, 2024
  11. added a commit that references this issue on Dec 8, 2024
  12. added 2 commits that reference 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 fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions