Skip to content

Commit df70ca5

Browse files
authored
Fix #912 multibyte character breaks message (#914)
* Fix #912 multibyte character breaks message * Add change file * Fix clippy
1 parent cc67680 commit df70ca5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

.changes/912-unicode-messages.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
Adjust payload formatting to handle multibyte characters in front-end message
5+
payloads.

tauri/src/app/runner.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ fn build_webview(
302302

303303
let mut w = webview.clone();
304304
webview.bind("__TAURI_INVOKE_HANDLER__", move |_, arg| {
305-
// transform `[payload]` to `payload`
306-
let arg = arg.chars().skip(1).take(arg.len() - 2).collect::<String>();
305+
let arg = format_arg(arg);
307306
if arg == r#"{"cmd":"__initialized"}"# {
308307
let source = if has_splashscreen && !initialized_splashscreen {
309308
initialized_splashscreen = true;
@@ -379,6 +378,15 @@ fn get_api_error_message(arg: &str, handler_error_message: String) -> String {
379378
)
380379
}
381380

381+
// Transform `[payload]` to `payload`
382+
fn format_arg(arg: &str) -> String {
383+
arg
384+
.chars()
385+
.skip(1)
386+
.take(arg.chars().count() - 2)
387+
.collect::<String>()
388+
}
389+
382390
#[cfg(test)]
383391
mod test {
384392
use super::Content;
@@ -477,4 +485,13 @@ mod test {
477485
}
478486
}
479487
}
488+
489+
#[test]
490+
fn test_format_arg() {
491+
let input = &["[payload]", "[påyløad]"];
492+
let expected = &[String::from("payload"), String::from("påyløad")];
493+
for (i, e) in input.iter().zip(expected) {
494+
assert_eq!(&super::format_arg(i), e);
495+
}
496+
}
480497
}

0 commit comments

Comments
 (0)