on master help sign in
Handle UTF-16 encoding errors with replacement characters
commit9e11d669791bd214cb61a76ce7a337033566ea6c authorsharkdp <davidpeter@web.de> dateSun 10 Feb 2019, 09:20 (8 years ago) parentfa3244f
1 file changed+4−4
src/printer.rs+4−4
src/printer.rs+4−4
@@ -261,11 +261,11 @@ impl<'a> Printer for InteractivePrinter<'a> {
261261 return Ok(());
262262 }
263263 ContentType::UTF_16LE => UTF_16LE
264− .decode(&line_buffer, DecoderTrap::Strict)
265− .unwrap_or("Invalid UTF-16LE".into()),
264+ .decode(&line_buffer, DecoderTrap::Replace)
265+ .map_err(|_| "Invalid UTF-16LE")?,
266266 ContentType::UTF_16BE => UTF_16BE
267− .decode(&line_buffer, DecoderTrap::Strict)
268− .unwrap_or("Invalid UTF-16BE".into()),
267+ .decode(&line_buffer, DecoderTrap::Replace)
268+ .map_err(|_| "Invalid UTF-16BE")?,
269269 _ => String::from_utf8_lossy(&line_buffer).to_string(),
270270 };
271271