Skip to content

Commit e663bdd

Browse files
authored
fix(core): svg mime type (#2129)
1 parent df32ff5 commit e663bdd

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

.changes/fix-svg-mime-type.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-runtime-wry": patch
3+
"tauri": patch
4+
---
5+
6+
Fixes SVG loading on custom protocol.

core/tauri-runtime-wry/src/mime_type.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ impl MimeType {
6363

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

71-
if mime == MIMETYPE_PLAIN {
72-
return Self::parse_from_uri(uri).to_string();
73+
match mime {
74+
Some(mime) if mime == MIMETYPE_PLAIN => Self::parse_from_uri(uri).to_string(),
75+
None => Self::parse_from_uri(uri).to_string(),
76+
Some(mime) => mime.to_string(),
7377
}
74-
75-
mime.to_string()
7678
}
7779
}
7880

0 commit comments

Comments
 (0)