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

pathname2url: normalize forward slashes to backslashes before processing #183

Open
wants to merge 1 commit into
base: mingw-v3.12.7
Choose a base branch
from

Conversation

Kreijstal
Copy link

@Kreijstal Kreijstal commented Nov 19, 2024

fixes #182
Fix pathname2url to handle paths with forward slashes correctly by normalizing all forward slashes to backslashes at the start of processing. This prevents issues where paths containing forward slashes would result in malformed URLs with double slashes after the drive letter (e.g. "C://Users" instead of "C:/Users").

Before:

>>> pathname2url("C:/Users/example")
'//C://Users/example'

After:

>>> pathname2url("C:/Users/example")
'//C:/Users/example'

The function now handles both forward and backward slashes consistently.

Fix pathname2url to handle paths with forward slashes correctly by normalizing
all forward slashes to backslashes at the start of processing. This prevents
issues where paths containing forward slashes would result in malformed URLs
with double slashes after the drive letter (e.g. "C://Users" instead of "C:/Users").

Before:
>>> pathname2url("C:/Users/example")
'//C://Users/example'

After:
>>> pathname2url("C:/Users/example")
'//C:/Users/example'

The function now handles both forward and backward slashes consistently.
@Kreijstal
Copy link
Author

is test_urllib buggy in purpose? why 3 forward slashes, that doesn't work

@lazka
Copy link
Member

lazka commented Nov 19, 2024

How is this related to the mingw port? Is it a regression we introduced?

@Kreijstal
Copy link
Author

Kreijstal commented Nov 19, 2024

How is this related to the mingw port? Is it a regression we introduced?

jupyterlab on normal windows seem to open the browser but on mingw it doesn't
would you recommend to patch jupyterlab on mingw instead?

@lazka
Copy link
Member

lazka commented Nov 19, 2024

Using the official CPython build:

Python 3.12.7 (tags/v3.12.7:0b05ead, Oct  1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> urllib.request.pathname2url("C:/Users/example")
'///C://Users/example'
>>>

Not saying that there isn't a problem, but I doubt this is the root cause.

@naveen521kk
Copy link
Member

naveen521kk commented Nov 23, 2024

I think it has to do something with our conversion system from \\ to /. One thing I could observe is:

Python 3.12.7 (main, Nov  3 2024, 19:54:34)  [GCC 14.2.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.request import pathname2url
>>> pathname2url(r"C:/hello")
'///C://hello'
>>> pathname2url(r"C:\\hello")
'///C:/hello'
>>>

that's why I think things work with the official Python but not with ours. Trying out MSYSTEM= jupyter lab seems to open my browser without any issues.

I think this should be fixed upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

urlib.request has the wrong output? or is jupyter understanding
3 participants