Skip to content

Commit 85e77fb

Browse files
reupenlucasfernog
andauthored
fix: correct MIME type of .txt files (ref: #6762) (#7111)
Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 3327dd6 commit 85e77fb

6 files changed

Lines changed: 26 additions & 15 deletions

File tree

‎.changes/txt-mime-type.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": patch
3+
---
4+
5+
Correctly determine MIME type of `.txt` files.

‎.github/workflows/test-core.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ jobs:
9393
cargo update -p time --precise 0.3.15
9494
cargo update -p ignore --precise 0.4.18
9595
cargo update -p raw-window-handle --precise 0.5.0
96+
cargo update -p cargo_toml:0.15.3 --precise 0.15.2
9697
9798
- name: test
9899
run: cargo test --target ${{ matrix.platform.target }} ${{ matrix.features.args }}

‎core/tauri-codegen/src/context.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
176176
.tauri
177177
.security
178178
.dev_csp
179-
.clone()
180-
.or_else(|| config.tauri.security.csp.clone())
179+
.as_ref()
180+
.or(config.tauri.security.csp.as_ref())
181181
} else {
182-
config.tauri.security.csp.clone()
182+
config.tauri.security.csp.as_ref()
183183
};
184184
if csp.is_some() {
185185
options = options.with_csp();

‎core/tauri-macros/src/command_module.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ pub fn command_handler(attributes: HandlerAttributes, function: ItemFn) -> Token
272272
pub fn command_test(attributes: HandlerTestAttributes, function: ItemFn) -> TokenStream2 {
273273
let allowlist = attributes.allowlist;
274274
let error_message = attributes.error_message.as_str();
275-
let signature = function.sig.clone();
275+
let signature = &function.sig;
276276

277277
let enum_variant_name = function.sig.ident.to_string().to_lower_camel_case();
278278
let response = match attributes.allowlist_check_kind {
279279
AllowlistCheckKind::Runtime => {
280-
let test_name = function.sig.ident.clone();
280+
let test_name = &signature.ident;
281281
quote!(super::Cmd::#test_name(crate::test::mock_invoke_context()))
282282
}
283283
AllowlistCheckKind::Serde => quote! {

‎core/tauri-utils/src/mime_type.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ pub enum MimeType {
1818
Js,
1919
Json,
2020
Jsonld,
21+
Mp4,
2122
OctetStream,
2223
Rtf,
2324
Svg,
24-
Mp4,
25+
Txt,
2526
}
2627

2728
impl std::fmt::Display for MimeType {
@@ -34,10 +35,11 @@ impl std::fmt::Display for MimeType {
3435
MimeType::Js => "text/javascript",
3536
MimeType::Json => "application/json",
3637
MimeType::Jsonld => "application/ld+json",
38+
MimeType::Mp4 => "video/mp4",
3739
MimeType::OctetStream => "application/octet-stream",
3840
MimeType::Rtf => "application/rtf",
3941
MimeType::Svg => "image/svg+xml",
40-
MimeType::Mp4 => "video/mp4",
42+
MimeType::Txt => MIMETYPE_PLAIN,
4143
};
4244
write!(f, "{mime}")
4345
}
@@ -62,9 +64,10 @@ impl MimeType {
6264
Some("json") => Self::Json,
6365
Some("jsonld") => Self::Jsonld,
6466
Some("mjs") => Self::Js,
67+
Some("mp4") => Self::Mp4,
6568
Some("rtf") => Self::Rtf,
6669
Some("svg") => Self::Svg,
67-
Some("mp4") => Self::Mp4,
70+
Some("txt") => Self::Txt,
6871
// Assume HTML when a TLD is found for eg. `wry:://tauri.app` | `wry://hello.com`
6972
Some(_) => fallback,
7073
// using octet stream according to this:
@@ -133,14 +136,17 @@ mod tests {
133136
let mjs: String = MimeType::parse_from_uri("https://example.com/bundled.mjs").to_string();
134137
assert_eq!(mjs, String::from("text/javascript"));
135138

139+
let mp4: String = MimeType::parse_from_uri("https://example.com/video.mp4").to_string();
140+
assert_eq!(mp4, String::from("video/mp4"));
141+
136142
let rtf: String = MimeType::parse_from_uri("https://example.com/document.rtf").to_string();
137143
assert_eq!(rtf, String::from("application/rtf"));
138144

139145
let svg: String = MimeType::parse_from_uri("https://example.com/picture.svg").to_string();
140146
assert_eq!(svg, String::from("image/svg+xml"));
141147

142-
let mp4: String = MimeType::parse_from_uri("https://example.com/video.mp4").to_string();
143-
assert_eq!(mp4, String::from("video/mp4"));
148+
let txt: String = MimeType::parse_from_uri("https://example.com/file.txt").to_string();
149+
assert_eq!(txt, String::from("text/plain"));
144150

145151
let custom_scheme = MimeType::parse_from_uri("wry://tauri.app").to_string();
146152
assert_eq!(custom_scheme, String::from("text/html"));

‎core/tauri/src/event.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,13 @@ mod test {
282282

283283
// check to see if on_event properly grabs the stored function from listen.
284284
#[test]
285-
fn check_on_event(e in "[a-z]+", d in "[a-z]+") {
285+
fn check_on_event(key in "[a-z]+", d in "[a-z]+") {
286286
let listeners: Listeners = Default::default();
287-
// clone e as the key
288-
let key = e.clone();
287+
289288
// call listen with e and the event_fn dummy func
290-
listeners.listen(e.clone(), None, event_fn);
289+
listeners.listen(key.clone(), None, event_fn);
291290
// call on event with e and d.
292-
listeners.trigger(&e, None, Some(d));
291+
listeners.trigger(&key, None, Some(d));
293292

294293
// lock the mutex
295294
let l = listeners.inner.handlers.lock().unwrap();

0 commit comments

Comments
 (0)