Skip to content

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

Description

@vcfxb

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:

fn convert_uri_to_path(s: &str) -> Result<PathBuf, egui::load::LoadError> {

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions