Skip to content

Use pathlib.Path.as_uri to format browser open redirect files - #1682

Open
aadamowski wants to merge 1 commit into
jupyter-server:mainfrom
aadamowski:main
Open

aadamowski wants to merge 1 commit into
jupyter-server:mainfrom
aadamowski:main

Conversation

@aadamowski

Copy link
Copy Markdown

Summary

Uses pathlib.Path.as_uri() to construct standards-compliant local file URLs for the browser redirect file utility.

Details

The combination of urljoin("file:", pathname2url(...)) generates non-compliant file:/home/... URI strings on Unix platforms. Strict POSIX URL handlers (such as xdg-open under desktop environments like LXQt) fail to resolve this format as a local file, breaking automatic browser launch pipelines.

Migrating this formatting layer to pathlib.Path.as_uri() ensures robust, platform-aware URI compilation. This guarantees valid triple-slash formats (file:///...) for both the background subprocess execution thread and the terminal diagnostic logs.

Testing

I've ran pytest as documented in CONTRIBUTING.rst#running-tests.

All tests pass, except for tests/services/sessions/test_api.py::test_restart_kernel[jp_server_config0] which on my machine also fails with code on the main branch, with assert 1 == 0. This seems to be a pre-existing broken test.

@aadamowski
aadamowski marked this pull request as draft July 22, 2026 00:12
@aadamowski
aadamowski marked this pull request as ready for review July 22, 2026 00:13
@aadamowski

Copy link
Copy Markdown
Author

Rebase against main.

Ran hatch run test:nowarn locally:

 1165 passed, 21 skipped, 277 warnings in 355.66s (0:05:55) 

Unfortunately, looks like GitHub actions continuous integration infra for the project is currently broken, hence the failing checks (which segfault on spinup). I also observed some flaky tests which can spuriously fail on both my branch and on main (notably, test_restart_kernel). None of these should have connection to my commits.

@jasongrout jasongrout left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

The existing urljoin pattern constructs non-compliant file URIs containing
a single leading slash on Unix platforms. This breaks system-level browser
dispatching tools like xdg-open on strict desktop environments.

Replacing the urljoin implementation with standard library pathlib methods
ensures that valid, platform-aware file URLs are universally generated
and logged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants