From fb94d470a8ccd1335405d2de75bb54912b4f56c2 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 5 Dec 2025 17:38:27 +0800 Subject: [PATCH 1/5] fix(process): improve stdout encoding handling in read_line functions #1471 --- plugins/shell/src/process/mod.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/shell/src/process/mod.rs b/plugins/shell/src/process/mod.rs index 6f350c181..16f7aeb42 100644 --- a/plugins/shell/src/process/mod.rs +++ b/plugins/shell/src/process/mod.rs @@ -401,6 +401,7 @@ fn read_raw_bytes) -> CommandEvent + Send + Copy + 'static>( tx: Sender, wrapper: F, ) { + let encoder = get_system_encoding(); loop { let result = reader.fill_buf(); match result { @@ -409,8 +410,10 @@ fn read_raw_bytes) -> CommandEvent + Send + Copy + 'static>( if length == 0 { break; } + let (cow, _, _) = encoder.decode(buf); + let decode_bytes = cow.into_owned().into_bytes(); let tx_ = tx.clone(); - let _ = block_on_task(async move { tx_.send(wrapper(buf.to_vec())).await }); + let _ = block_on_task(async move { tx_.send(wrapper(decode_bytes)).await }); reader.consume(length); } Err(e) => { @@ -428,6 +431,7 @@ fn read_line) -> CommandEvent + Send + Copy + 'static>( tx: Sender, wrapper: F, ) { + let encoder = get_system_encoding(); loop { let mut buf = Vec::new(); match tauri::utils::io::read_line(&mut reader, &mut buf) { @@ -435,8 +439,10 @@ fn read_line) -> CommandEvent + Send + Copy + 'static>( if n == 0 { break; } + let (cow, _, _) = encoder.decode(&buf); + let decode_bytes = cow.into_owned().into_bytes(); let tx_ = tx.clone(); - let _ = block_on_task(async move { tx_.send(wrapper(buf)).await }); + let _ = block_on_task(async move { tx_.send(wrapper(decode_bytes)).await }); } Err(e) => { let tx_ = tx.clone(); @@ -468,6 +474,21 @@ fn spawn_pipe_reader) -> CommandEvent + Send + Copy + 'static>( }); } +#[cfg(windows)] +const fn get_system_encoding() -> &'static Encoding { + use encoding_rs::WINDOWS_1252; + WINDOWS_1252 +} + +#[cfg(unix)] +const fn get_system_encoding() -> &'static Encoding { + // ! Remove afetr dev + use encoding_rs::WINDOWS_1252; + WINDOWS_1252 + // use encoding_rs::UTF_8; + // UTF_8 +} + // tests for the commands functions. #[cfg(test)] mod tests { From 6d65b399534dff52b74505ccf2bfe0a3e5f8ea78 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 5 Dec 2025 17:40:58 +0800 Subject: [PATCH 2/5] fix(process): remove unnecessary encoding in read_raw_bytes function --- plugins/shell/src/process/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/shell/src/process/mod.rs b/plugins/shell/src/process/mod.rs index 16f7aeb42..28c91d339 100644 --- a/plugins/shell/src/process/mod.rs +++ b/plugins/shell/src/process/mod.rs @@ -401,7 +401,6 @@ fn read_raw_bytes) -> CommandEvent + Send + Copy + 'static>( tx: Sender, wrapper: F, ) { - let encoder = get_system_encoding(); loop { let result = reader.fill_buf(); match result { @@ -410,10 +409,8 @@ fn read_raw_bytes) -> CommandEvent + Send + Copy + 'static>( if length == 0 { break; } - let (cow, _, _) = encoder.decode(buf); - let decode_bytes = cow.into_owned().into_bytes(); let tx_ = tx.clone(); - let _ = block_on_task(async move { tx_.send(wrapper(decode_bytes)).await }); + let _ = block_on_task(async move { tx_.send(wrapper(buf.to_vec())).await }); reader.consume(length); } Err(e) => { From fd16c14f6fbdf6d5b5529bacf5a90fb9b546bbac Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 5 Dec 2025 17:42:15 +0800 Subject: [PATCH 3/5] fix(process): streamline system encoding handling for cross-platform compatibility --- plugins/shell/src/process/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/shell/src/process/mod.rs b/plugins/shell/src/process/mod.rs index 28c91d339..ed83b60b4 100644 --- a/plugins/shell/src/process/mod.rs +++ b/plugins/shell/src/process/mod.rs @@ -23,6 +23,10 @@ const NEWLINE_BYTE: u8 = b'\n'; use tauri::async_runtime::{block_on as block_on_task, channel, Receiver, Sender}; pub use encoding_rs::Encoding; +#[cfg(not(windows))] +use encoding_rs::UTF_8; +#[cfg(windows)] +use encoding_rs::WINDOWS_1252; use os_pipe::{pipe, PipeReader, PipeWriter}; use serde::Serialize; use shared_child::SharedChild; @@ -473,17 +477,12 @@ fn spawn_pipe_reader) -> CommandEvent + Send + Copy + 'static>( #[cfg(windows)] const fn get_system_encoding() -> &'static Encoding { - use encoding_rs::WINDOWS_1252; WINDOWS_1252 } -#[cfg(unix)] +#[cfg(not(windows))] const fn get_system_encoding() -> &'static Encoding { - // ! Remove afetr dev - use encoding_rs::WINDOWS_1252; - WINDOWS_1252 - // use encoding_rs::UTF_8; - // UTF_8 + UTF_8 } // tests for the commands functions. From 2cf3cb59a1f136b63e8e5a4acba18b37751d0339 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 5 Dec 2025 17:58:01 +0800 Subject: [PATCH 4/5] fix(process): correct stdout encoding issue in readline handling --- .changes/fix-stdout-readline-encoding.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/fix-stdout-readline-encoding.md diff --git a/.changes/fix-stdout-readline-encoding.md b/.changes/fix-stdout-readline-encoding.md new file mode 100644 index 000000000..8d32deab8 --- /dev/null +++ b/.changes/fix-stdout-readline-encoding.md @@ -0,0 +1,6 @@ +--- +"shell": patch +"shell-js": patch +--- + +Fix incorrect stdout encoding when readline. \ No newline at end of file From f5858bf1f3f383d42c59e6a0193562bf9ea52379 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 5 Dec 2025 18:51:20 +0800 Subject: [PATCH 5/5] fix(process): unify system encoding handling to compectiable with rust 1.77.2 --- plugins/shell/src/process/mod.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/plugins/shell/src/process/mod.rs b/plugins/shell/src/process/mod.rs index ed83b60b4..757464e52 100644 --- a/plugins/shell/src/process/mod.rs +++ b/plugins/shell/src/process/mod.rs @@ -24,9 +24,9 @@ use tauri::async_runtime::{block_on as block_on_task, channel, Receiver, Sender} pub use encoding_rs::Encoding; #[cfg(not(windows))] -use encoding_rs::UTF_8; +use encoding_rs::UTF_8 as SYSTEM_ENCODING; #[cfg(windows)] -use encoding_rs::WINDOWS_1252; +use encoding_rs::WINDOWS_1252 as SYSTEM_ENCODING; use os_pipe::{pipe, PipeReader, PipeWriter}; use serde::Serialize; use shared_child::SharedChild; @@ -432,7 +432,6 @@ fn read_line) -> CommandEvent + Send + Copy + 'static>( tx: Sender, wrapper: F, ) { - let encoder = get_system_encoding(); loop { let mut buf = Vec::new(); match tauri::utils::io::read_line(&mut reader, &mut buf) { @@ -440,7 +439,7 @@ fn read_line) -> CommandEvent + Send + Copy + 'static>( if n == 0 { break; } - let (cow, _, _) = encoder.decode(&buf); + let (cow, _, _) = SYSTEM_ENCODING.decode(&buf); let decode_bytes = cow.into_owned().into_bytes(); let tx_ = tx.clone(); let _ = block_on_task(async move { tx_.send(wrapper(decode_bytes)).await }); @@ -475,16 +474,6 @@ fn spawn_pipe_reader) -> CommandEvent + Send + Copy + 'static>( }); } -#[cfg(windows)] -const fn get_system_encoding() -> &'static Encoding { - WINDOWS_1252 -} - -#[cfg(not(windows))] -const fn get_system_encoding() -> &'static Encoding { - UTF_8 -} - // tests for the commands functions. #[cfg(test)] mod tests {