From 9e11d669791bd214cb61a76ce7a337033566ea6c Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 10 Feb 2019 09:20:02 +0100 Subject: [PATCH] Handle UTF-16 encoding errors with replacement characters --- src/printer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 0c549feb..45f0642f 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -261,11 +261,11 @@ impl<'a> Printer for InteractivePrinter<'a> { return Ok(()); } ContentType::UTF_16LE => UTF_16LE - .decode(&line_buffer, DecoderTrap::Strict) - .unwrap_or("Invalid UTF-16LE".into()), + .decode(&line_buffer, DecoderTrap::Replace) + .map_err(|_| "Invalid UTF-16LE")?, ContentType::UTF_16BE => UTF_16BE - .decode(&line_buffer, DecoderTrap::Strict) - .unwrap_or("Invalid UTF-16BE".into()), + .decode(&line_buffer, DecoderTrap::Replace) + .map_err(|_| "Invalid UTF-16BE")?, _ => String::from_utf8_lossy(&line_buffer).to_string(), };