Image/file loader has issues when file uri contains escaped spaces.

Open Beginner friendly
#8,288 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
desktop

Research direction

Start in crates/egui_extras/src/loaders/file_loader.rs at the linked line and reproduce loading a Windows file:// URI containing an escaped space such as %20. Confirm the loader resolves the URI to the intended file path and that the image loads successfully instead of failing to find the file.

Written by the indexing model from the issue text.

Description

bug

Describe the bug

For file:// URIs to images, if there is a URI-escaped space (or perhaps other charactter, I haven't checked), it will cause issues finding and loading the image/file (at least on Windows 11). I suspect this is due to this function:
https://github.com/emilk/egui/blob/68b74530b7848cef6bff4efc5fc9906bfbd1e8ca/crates/egui_extras/src/loaders/file_loader.rs#L32
which does not handle file:// URIs as actual URIs with escaping, and instead just strips the prefix.

Here's the log message with a file path, showing a %20 representing a space in my username.

[desktop\src\view\search\col_format.rs:22:35] uri.as_str() = "file:///C:/Users/alfri/AppData/Local/Venus%20Xeon-Blonde/Oshibana/cache/symbology-cache/U.svg"

Screenshots

With initial code:

ui.image(uri.as_str());
Image

With workaround:

match uri.to_file_path() {
    Ok(path) => {
        let reformatted = if cfg!(windows) {
            format!("file:///{}", path.display())
        } else {
            format!("file://{}", path.display())
        };

        ui.image(reformatted);
    },
    Err(_) => {
        ui.image(uri.as_str());
    },
};
Image

Desktop (please complete the following information):

  • OS: Windows 11
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
73

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from emilk/egui

All issues in emilk/egui

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.