From 238f5eccd3c9f9cb7aa52e30b42ae8cce8544a09 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 2 Aug 2023 15:45:05 +1000 Subject: [PATCH] Fix `PrintThread`: Read stderr as bytes instead of str to accept non-utf-8 characters. Fixed #841 Signed-off-by: Jiahao XU --- src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 91536c3e..45532ed3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3828,14 +3828,20 @@ impl PrintThread { // location to another. let print = thread::spawn(move || { let mut stderr = BufReader::with_capacity(4096, pipe_reader); - let mut line = String::with_capacity(20); - let mut stdout = io::stdout(); + let mut line = Vec::with_capacity(20); + let stdout = io::stdout(); - // read_line returns 0 on Eof - while stderr.read_line(&mut line).unwrap() != 0 { - writeln!(&mut stdout, "cargo:warning={}", line).ok(); + // read_until returns 0 on Eof + while stderr.read_until(b'\n', &mut line).unwrap() != 0 { + { + let mut stdout = stdout.lock(); + + stdout.write_all(b"cargo:warning=").unwrap(); + stdout.write_all(&line).unwrap(); + stdout.write_all(b"\n").unwrap(); + } - // read_line does not clear the buffer + // read_until does not clear the buffer line.clear(); } });