Răsfoiți Sursa

fix(core): svg mime type (#2129)

Lucas Fernandes Nogueira 4 ani în urmă
părinte
comite
e663bdd593
2 a modificat fișierele cu 15 adăugiri și 7 ștergeri
  1. 6 0
      .changes/fix-svg-mime-type.md
  2. 9 7
      core/tauri-runtime-wry/src/mime_type.rs

+ 6 - 0
.changes/fix-svg-mime-type.md

@@ -0,0 +1,6 @@
+---
+"tauri-runtime-wry": patch
+"tauri": patch
+---
+
+Fixes SVG loading on custom protocol.

+ 9 - 7
core/tauri-runtime-wry/src/mime_type.rs

@@ -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()
   }
 }