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.url2pathname() mishandles non-empty authority sections on POSIX #126838

Closed
barneygale opened this issue Nov 14, 2024 · 1 comment
Closed
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@barneygale
Copy link
Contributor

barneygale commented Nov 14, 2024

Bug report

Bug description:

URLs supplied to urllib.request.url2pathname() may include a non-empty authority (netloc), such as a hostname.

On Windows, these are correctly decoded (mostly):

>>> url2pathname('//localhost/c:/foo.txt')
'C:\\foo.txt'  # OK
>>> url2pathname('//server/share')
'\\\\server\\share'  # OK

But on POSIX, any non-empty authority except localhost is preserved in the path:

>>> url2pathname('//myhostname/etc/hosts')
'//myhostname/etc/hosts'  # expected '/etc/hosts'
>>> url2pathname('//server/share')
'//server/share'  # expected URLError ('server' is not local)

Per RFC 8089 this isn't correct.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@barneygale barneygale added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Nov 14, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Nov 14, 2024
… on POSIX

Adjust `urllib.request.url2pathname()` to parse the URL authority and path
with `urlsplit()` on POSIX. If the authority is empty or resolves to the
current host, it is ignored and the URL path is used as the pathname.
If not, we raise `URLError`.
barneygale added a commit to barneygale/cpython that referenced this issue Nov 19, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Nov 19, 2024
@barneygale
Copy link
Contributor Author

Closing - dupe of #123599

@barneygale barneygale closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2024
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 stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant