Skip to content

Windows: links open through the shell, not explorer.exe (#2085) - #3305

Open
ljkx wants to merge 2 commits into
storytold:mainfrom
ljkx:windows-links-shell-execute
Open

ljkx wants to merge 2 commits into
storytold:mainfrom
ljkx:windows-links-shell-execute

Conversation

@ljkx

@ljkx ljkx commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2085

Cause

On Windows, open_with_system (apps/gridcraft/src/main.rs) opened links by spawning explorer <url>. explorer.exe parses its own command line, and it doesn't treat a URL as one opaque argument. I measured this on Windows 11 by sending URLs through the same call to a local server that logs each request:

URL passed to explorer What happened
http://127.0.0.1:8765/h1 the browser asked for /h1
…/q2?x the browser asked for /q2?x
…/q1?x=1, …/q3/a=b, …/t1?x=1&y=2 no request; explorer opened the Documents folder
…/q6/a,b the browser asked for /q6/a (cut at the comma)
"…/L1?redeem=<2100 chars>&ithint=folder" (quoted) the browser asked for the first 259 characters only

So any link with a query string (?id=1) opened the user's Documents folder. That is the reporter's "Hyperlink opens my I:\onedrive\documents instead of the web address". A long share link that does reach the browser loses its query past 259 characters, which matches the earlier report of landing on the OneDrive root instead of the subfolder. Quoting the argument fixes = and , but not the length cut, so explorer.exe can't be made to work for URLs.

Fix

On Windows, links go to the shell with ShellExecuteExW, which passes the URL whole to the registered browser or mail handler. Python's os.startfile uses the same call, and with it the same URLs arrived intact in the experiment above. The workspace forbids unsafe, so the call goes through the open crate (open::that_detached with its shellexecute-on-windows feature). That crate is already in Cargo.lock at 5.4.4 (through egui_kittest), and so is its one extra dependency for this feature, dunce. It is added as a Windows-only dependency, pinned exactly, like the macOS objc2 crates. The lockfile change is two dependency-list lines.

The link policy is unchanged: classify still lets only http, https and mailto through. macOS (open) and Linux/BSD (xdg-open) are unchanged: the platform-specific part moved into a launch function with a cfg(windows) and a cfg(not(windows)) body.

Tests

  • open_with_system_tests::a_long_address_with_a_query_reaches_the_browser_whole (Windows only) binds a local listener, calls open_with_system with http://127.0.0.1:<port>/:f:/g/personal/a1/EaB?resid=A1%21123&ithint=folder,oneup&redeem=<2048 × x>#Sheet2-B7, and asserts that the first request the browser makes there has exactly that path and query. A browser never sends the fragment, so the page served for that request asks for /fragment/<fragment>, and the test asserts that this second request is /fragment/Sheet2-B7. It is #[ignore] because it starts the machine's default browser, which CI shouldn't do. Run it with cargo test -p gridcraft --bin gridcraft -- --ignored a_long_address.
  • Fails without the fix: with the Windows launch temporarily put back to Command::new("explorer").arg(target), the test fails after 30 s with left: None (no request ever arrived), and an Explorer window showing Documents was left open. With the fix it passes.
  • cargo test -p gridcraft --bin gridcraft -- --include-ignored: 35 passed. cargo clippy --all-targets -p gridcraft -- -D warnings and cargo fmt -p gridcraft --check are clean (Windows 11).

Not changed

Summary by CodeRabbit

  • Bug Fixes
    • Improved how external links open on Windows, using the system’s default handler.
    • Long URLs retain their query details when opened, helping ensure the browser receives the intended link.

explorer.exe parses its own command line: an `=` anywhere in a URL (any
query string) made it open the Documents folder, a `,` cut the URL there,
and it kept only the first 259 characters. Links now go to ShellExecuteExW
through the `open` crate (already in Cargo.lock), Windows only.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Windows external links now launch through open::that_detached. macOS uses open, and other non-Windows platforms use xdg-open. An ignored Windows test checks browser requests for a long URL’s query and fragment-derived path.

Changes: Windows external-link launching

Layer / File(s) Summary
Configure, launch, and validate external URLs
apps/gridcraft/Cargo.toml, apps/gridcraft/src/main.rs
Adds the Windows-only open dependency and platform-specific launch functions. The ignored Windows test checks that the browser requests the long query path and then the fragment-derived path.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

Suggested reviewers: vangel76, aiongg, dylanmtaylor

Merge Risk: Minimal · up to 0fcb4

No actionable merge-blocking risk remains established for this change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: Windows links now open through the shell instead of explorer.exe.
Linked Issues check Passed #2085 asks whether the complete OneDrive URL survives import and opening. open_with_system still restricts links to http, https, and mailto, and Windows now passes the URL to `open::that_detac…
Out of Scope Changes check Passed The changes are limited to Windows URL launching, its Windows-only dependency, and a focused end-to-end regression test for #2085. The non-Windows launch behavior and link policy remain unchanged. No …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

#2085 asks whether the complete OneDrive URL survives import and opening. open_with_system still restricts links to http, https, and mailto, and Windows now passes the URL to open::that_detached instead of explorer.exe. The added Windows-only test checks the exact long path and query received by the browser, then checks the fragment through a follow-up request. The PR also identifies existing XLSX import code and tests that preserve the target and fragment.

Full details: Out of Scope Changes check

Explanation

The changes are limited to Windows URL launching, its Windows-only dependency, and a focused end-to-end regression test for #2085. The non-Windows launch behavior and link policy remain unchanged. No unrelated change is evident in the reviewed diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 1 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.0)

Clippy execution timed out

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 56d6d6b and 0fcb4be.

Files selected for processing: 1
  • apps/gridcraft/src/main.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

A browser never sends the fragment, so the page served for the first
request asks for /fragment/<fragment> and the test checks that request.
@ljkx

ljkx commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai Thanks for the review. On the inconclusive linked-issue check:

  1. Import: already covered, with no change needed. read_hyperlinks (crates/xlsx/src/sheet_read/parts.rs, lines 11-19) takes the hyperlink relationship's Target as written and appends a location attribute as #fragment. crates/xlsx/src/tests/fixtures.rs:316 asserts that Target="https://example.com/a?b=1&amp;c=2" imports as https://example.com/a?b=1&c=2, and crates/xlsx/src/tests/roundtrip.rs:207 round-trips https://example.com/?a=1&b=2.
  2. Fragment: fixed in the second commit. The test URL now ends in #Sheet2-B7. A browser never sends the fragment, so the page served for the first request asks for /fragment/<fragment>, and the test asserts that request is /fragment/Sheet2-B7. It passes on Windows 11, together with the existing exact path-and-query assertion.
  3. macOS and Linux/BSD: not changed. open and xdg-open get the URL as a single argv entry, with no command-line parsing of their own like explorer.exe's, so the problem in OneDrive folder hyperlinks reportedly open drive root instead of intended subfolder #2085 doesn't apply there.
  4. Reproduction: the issue has no shareable URL, since the reporter asked not to publish private share links. The PR description's table gives the measured behaviour of explorer.exe for =, , and long URLs. That covers both reported symptoms: Documents opening instead of the browser, and a share link losing its subfolder.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -eu
ast-grep outline crates/xlsx/src/sheet_read/parts.rs --match read_hyperlinks --view expanded
ast-grep outline crates/xlsx/src/tests/fixtures.rs --items all
ast-grep outline crates/xlsx/src/tests/roundtrip.rs --items all
ast-grep outline apps/gridcraft/src/main.rs --match 'open_with_system|launch|a_long_address' --items all --view expanded
sed -n '1,45p' crates/xlsx/src/sheet_read/parts.rs
sed -n '290,330p' crates/xlsx/src/tests/fixtures.rs
sed -n '185,225p' crates/xlsx/src/tests/roundtrip.rs
rg -n -C 65 'fn open_with_system|fn a_long_address_with_a_query_reaches_the_browser_whole' apps/gridcraft/src/main.rs

Length of output: 25369


@ljkx Thanks for the clarification and the fragment test update. The inspected code supports your explanation:

  • read_hyperlinks preserves the relationship target and appends a nonempty location as a fragment. The fixture test checks that &amp; in the XML becomes & in the imported query.
  • The Windows browser test checks the exact long path and query. It then checks /fragment/Sheet2-B7, which verifies the fragment through browser-side JavaScript.
  • The non-Windows launcher passes the URL as one argument to open or xdg-open.

This addresses my linked-issue verification concern. A synthetic regression test is appropriate here; no private sharing URL is needed.

I verified the test code, but I did not run the Windows browser test. Your reported Windows 11 result supplies the runtime evidence. The original OneDrive report remains unconfirmed, but that does not invalidate this focused launcher fix.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

This branch has not been deployed

No deployments
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.

OneDrive folder hyperlinks reportedly open drive root instead of intended subfolder

1 participant