Skip to content

Commit

Permalink
fix(core): svg mime type (#2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 30, 2021
1 parent df32ff5 commit e663bdd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-svg-mime-type.md
@@ -0,0 +1,6 @@
---
"tauri-runtime-wry": patch
"tauri": patch
---

Fixes SVG loading on custom protocol.
16 changes: 9 additions & 7 deletions core/tauri-runtime-wry/src/mime_type.rs
Expand Up @@ -63,16 +63,18 @@ impl MimeType {

/// infer mimetype from content (or) URI if needed.
pub fn parse(content: &[u8], uri: &str) -> String {
let mime = match infer::get(content) {
Some(info) => info.mime_type(),
None => MIMETYPE_PLAIN,
let mime = if uri.ends_with(".svg") {
// when reading svg, we can't use `infer`
None
} else {
infer::get(content).map(|info| info.mime_type())
};

if mime == MIMETYPE_PLAIN {
return Self::parse_from_uri(uri).to_string();
match mime {
Some(mime) if mime == MIMETYPE_PLAIN => Self::parse_from_uri(uri).to_string(),
None => Self::parse_from_uri(uri).to_string(),
Some(mime) => mime.to_string(),
}

mime.to_string()
}
}

Expand Down

0 comments on commit e663bdd

Please sign in to comment.