From a171b89e062abd121f4b8b952c4f3d557c8966fa Mon Sep 17 00:00:00 2001 From: Olivier Lemasle Date: Thu, 2 Nov 2023 15:48:56 +0100 Subject: [PATCH] Fixes errors on command output The error occurs when the command output stream contains an invalid UTF-8 character, or ends with a multi-bytes UTF-8 character. Fixes #8110 --- .changes/fix-cmd-output-error.md | 7 +++++++ tooling/bundler/src/bundle/common.rs | 22 ++++++++++++++-------- tooling/cli/src/lib.rs | 22 ++++++++++++++-------- 3 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 .changes/fix-cmd-output-error.md diff --git a/.changes/fix-cmd-output-error.md b/.changes/fix-cmd-output-error.md new file mode 100644 index 000000000000..384095b81de4 --- /dev/null +++ b/.changes/fix-cmd-output-error.md @@ -0,0 +1,7 @@ +--- +"@tauri-apps/cli": patch:bug +"tauri-cli": patch:bug +"tauri-bundler": patch:bug +--- + +Fixes errors on command output, occuring when the output stream contains an invalid UTF-8 character, or ends with a multi-bytes UTF-8 character. diff --git a/tooling/bundler/src/bundle/common.rs b/tooling/bundler/src/bundle/common.rs index 712e3ebc9467..7e207faef0a5 100644 --- a/tooling/bundler/src/bundle/common.rs +++ b/tooling/bundler/src/bundle/common.rs @@ -169,11 +169,14 @@ impl CommandExt for Command { let mut lines = stdout_lines_.lock().unwrap(); loop { line.clear(); - if let Ok(0) = stdout.read_line(&mut line) { - break; + match stdout.read_line(&mut line) { + Ok(0) => break, + Ok(_) => { + debug!(action = "stdout"; "{}", line.trim_end()); + lines.extend(line.as_bytes().to_vec()); + } + Err(_) => (), } - debug!(action = "stdout"; "{}", &line[0..line.len() - 1]); - lines.extend(line.as_bytes().to_vec()); } }); @@ -185,11 +188,14 @@ impl CommandExt for Command { let mut lines = stderr_lines_.lock().unwrap(); loop { line.clear(); - if let Ok(0) = stderr.read_line(&mut line) { - break; + match stderr.read_line(&mut line) { + Ok(0) => break, + Ok(_) => { + debug!(action = "stderr"; "{}", line.trim_end()); + lines.extend(line.as_bytes().to_vec()); + } + Err(_) => (), } - debug!(action = "stderr"; "{}", &line[0..line.len() - 1]); - lines.extend(line.as_bytes().to_vec()); } }); diff --git a/tooling/cli/src/lib.rs b/tooling/cli/src/lib.rs index 80103335646a..fb1645e075c9 100644 --- a/tooling/cli/src/lib.rs +++ b/tooling/cli/src/lib.rs @@ -231,11 +231,14 @@ impl CommandExt for Command { let mut lines = stdout_lines_.lock().unwrap(); loop { line.clear(); - if let Ok(0) = stdout.read_line(&mut line) { - break; + match stdout.read_line(&mut line) { + Ok(0) => break, + Ok(_) => { + debug!(action = "stdout"; "{}", line.trim_end()); + lines.extend(line.as_bytes().to_vec()); + } + Err(_) => (), } - debug!(action = "stdout"; "{}", &line[0..line.len() - 1]); - lines.extend(line.as_bytes().to_vec()); } }); @@ -247,11 +250,14 @@ impl CommandExt for Command { let mut lines = stderr_lines_.lock().unwrap(); loop { line.clear(); - if let Ok(0) = stderr.read_line(&mut line) { - break; + match stderr.read_line(&mut line) { + Ok(0) => break, + Ok(_) => { + debug!(action = "stderr"; "{}", line.trim_end()); + lines.extend(line.as_bytes().to_vec()); + } + Err(_) => (), } - debug!(action = "stderr"; "{}", &line[0..line.len() - 1]); - lines.extend(line.as_bytes().to_vec()); } });