From 96f190b3ab6bd524e93dec426f3c73943262b703 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 27 Aug 2026 17:18:37 +0000 Subject: [PATCH] Use a url only when the doc path has a fragment ShellExecuteW does not handle urls very well so we try to avoid it as much as possible --- src/toolchain.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/toolchain.rs b/src/toolchain.rs index 57ed54a6c6..96eaa0a675 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -523,11 +523,21 @@ impl<'a> Toolchain<'a> { fragment: Option<&str>, ) -> anyhow::Result<()> { let relative = relative.as_ref(); - let mut doc_url = Url::from_file_path(self.doc_path(relative)?) - .ok() - .with_context(|| anyhow!("invalid doc file absolute path `{}`", relative.display()))?; - doc_url.set_fragment(fragment); - utils::open_browser(doc_url.to_string()) + let doc_path = self.doc_path(relative)?; + // HACK: If a fragment is needed then turn the path into a url + // We avoid doing this if a fragment isn't needed because + // `open_browser` can call `ShellExecuteW` on Windows which doesn't + // handle urls very well. See #5035. + if fragment.is_some() { + let mut doc_url = Url::from_file_path(&doc_path).ok().with_context(|| { + anyhow!("invalid doc file absolute path `{}`", relative.display()) + })?; + doc_url.set_fragment(fragment); + utils::open_browser(doc_url.to_string()) + } else { + // Otherwise use the filesystem path. + utils::open_browser(&doc_path) + } } /// Remove the toolchain from disk