mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
* Fix #912 multibyte character breaks message * Add change file * Fix clippy
This commit is contained in:
5
.changes/912-unicode-messages.md
Normal file
5
.changes/912-unicode-messages.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
Adjust payload formatting to handle multibyte characters in front-end message
|
||||
payloads.
|
||||
@@ -302,8 +302,7 @@ fn build_webview(
|
||||
|
||||
let mut w = webview.clone();
|
||||
webview.bind("__TAURI_INVOKE_HANDLER__", move |_, arg| {
|
||||
// transform `[payload]` to `payload`
|
||||
let arg = arg.chars().skip(1).take(arg.len() - 2).collect::<String>();
|
||||
let arg = format_arg(arg);
|
||||
if arg == r#"{"cmd":"__initialized"}"# {
|
||||
let source = if has_splashscreen && !initialized_splashscreen {
|
||||
initialized_splashscreen = true;
|
||||
@@ -379,6 +378,15 @@ fn get_api_error_message(arg: &str, handler_error_message: String) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
// Transform `[payload]` to `payload`
|
||||
fn format_arg(arg: &str) -> String {
|
||||
arg
|
||||
.chars()
|
||||
.skip(1)
|
||||
.take(arg.chars().count() - 2)
|
||||
.collect::<String>()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::Content;
|
||||
@@ -477,4 +485,13 @@ mod test {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_arg() {
|
||||
let input = &["[payload]", "[påyløad]"];
|
||||
let expected = &[String::from("payload"), String::from("påyløad")];
|
||||
for (i, e) in input.iter().zip(expected) {
|
||||
assert_eq!(&super::format_arg(i), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user