Skip to content

url2pathname() doesn't handle URL query or fragment components #136874

Closed

Description

@barneygale

Bug report

Bug description:

urllib.request.url2pathname() incorrectly treats URL query (?a=b&c=d) and fragment (#anchor) components as part of the URL path

>>> from urllib.request import url2pathname
>>> url2pathname('file://localhost/etc/hosts?foo=bar#badgers', require_scheme=True)
'/etc/hosts?foo=bar#badgers'  # expected '/etc/hosts'

I think they should be silently discarded as they have no bearing on the filesystem path (similar to how we discard the netloc if it's a local hostname).

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Jul 20, 2025
  2. added 3 commits that reference this issue on Jul 20, 2025
  3. added a commit that references this issue on Jul 21, 2025
  4. added a commit that references this issue on Jul 21, 2025
  5. emmatyping commented on Jul 23, 2025

    @emmatyping
    Member

    I believe this can be closed now that the PRs have been merged?

  6. barneygale commented on Jul 23, 2025

    @barneygale
    ContributorAuthor

    Yes, thanks for the nudge @emmatyping!

  7. added a commit that references this issue on Aug 4, 2025
  8. added a commit that references this issue on Aug 19, 2025
  9. added a commit that references this issue on Sep 9, 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

    stdlibStandard 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