Skip to content

open_that takes URL type#12352

Open
Caleb-T-Owens wants to merge 1 commit intomasterfrom
open-that-takes-a-url
Open

open_that takes URL type#12352
Caleb-T-Owens wants to merge 1 commit intomasterfrom
open-that-takes-a-url

Conversation

@Caleb-T-Owens
Copy link
Contributor

Replaces #12300.

This makes the same change, but opts to refactor the open_that function such that it now takes a Url which would have avoided the origional mistake.

The main fix is that the origional usage of .to_str_lossy never added a file:// protocol, which making use of Url::from_file_path does.

Replaces #12300.

This makes the same change, but opts to refactor the `open_that` function such that it now takes a `Url` which would have avoided the origional mistake.

The main fix is that the origional usage of `.to_str_lossy` never added a `file://` protocol, which making use of `Url::from_file_path` does.
Copilot AI review requested due to automatic review settings February 13, 2026 22:16
@vercel
Copy link

vercel bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
gitbutler-web Ignored Ignored Preview Feb 13, 2026 10:16pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the open_that function to accept a Url type instead of a string, aiming to prevent the bug fixed in #12300 where filesystem paths weren't properly converted to file:// URLs on Linux. The refactor ensures that all callers must provide a properly formed URL, making the API safer.

Changes:

  • Refactored open_that to accept &Url parameter instead of &str
  • Updated open_url to parse the string to Url before calling open_that
  • Modified show_in_finder on Linux to use Url::from_file_path to convert paths to file:// URLs
Comments suppressed due to low confidence (1)

crates/but-api/src/legacy/open.rs:22

  • The "file" scheme is missing from the allowed URL schemes list. Since this PR adds file:// URL support via Url::from_file_path, you need to add "file" to this whitelist, otherwise all file URLs will be rejected with "Invalid path scheme: file".
    if ![
        "http",
        "https",
        "mailto",
        "vscode",
        "vscodium",
        "vscode-insiders",
        "zed",
        "windsurf",
        "cursor",
        "trae",
    ]
    .contains(&target_url.scheme())

Comment on lines 125 to 127
let parent_str = parent.to_string_lossy();
open_that(&parent_str)
open_that(&Url::from_file_path(&parent_str))
.with_context(|| format!("Failed to open parent directory of '{path}' in file manager",))?;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

parent.to_string_lossy() returns a Cow<str>, not a &str or String. When passing this to Url::from_file_path, you should convert it to a proper path type. Consider using parent directly instead of converting to string and back:

let url = Url::from_file_path(parent)
    .map_err(|_| anyhow::anyhow!("Invalid file path: {}", path))?;
open_that(&url)

Copilot uses AI. Check for mistakes.
Comment on lines +120 to +121
open_that(&Url::from_file_path(&path))
.with_context(|| format!("Failed to open directory '{path}' in file manager"))?;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Url::from_file_path returns Result<Url, ()>, not Url. This code will fail to compile because you're trying to pass a Result to a function that expects a reference to a Url. You need to handle the error, for example:

let url = Url::from_file_path(&path)
    .map_err(|_| anyhow::anyhow!("Invalid file path: {}", path))?;
open_that(&url)

Copilot uses AI. Check for mistakes.
Comment on lines +126 to 127
open_that(&Url::from_file_path(&parent_str))
.with_context(|| format!("Failed to open parent directory of '{path}' in file manager",))?;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Url::from_file_path returns Result<Url, ()>, not Url. This code will fail to compile. You need to unwrap or handle the Result before passing to open_that.

Copilot uses AI. Check for mistakes.
Comment on lines +129 to +130
open_that(&Url::from_file_path(&path))
.with_context(|| format!("Failed to open '{path}' in file manager"))?;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Url::from_file_path returns Result<Url, ()>, not Url. This code will fail to compile. You need to unwrap or handle the Result before passing to open_that.

Copilot uses AI. Check for mistakes.
let mut cmd_errors = Vec::new();

for mut cmd in open::commands(path) {
for mut cmd in open::commands(target_url.path()) {
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Using target_url.path() extracts only the path component of the URL. For HTTP/HTTPS URLs like https://example.com/page, this would incorrectly pass /page instead of the full URL to open::commands(). For file URLs, this might work on Linux with xdg-open, but it's inconsistent. Consider using target_url.as_str() to pass the complete URL string to the open crate.

Suggested change
for mut cmd in open::commands(target_url.path()) {
for mut cmd in open::commands(target_url.as_str()) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant