Skip to content

Commit

Permalink
fix: allow invalid utf8 when decoding modules (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd authored May 23, 2024
1 parent 810aa7a commit 8854453
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/text_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ pub fn convert_to_utf8<'a>(
charset: &'_ str,
) -> Result<Cow<'a, str>, std::io::Error> {
match encoding_rs::Encoding::for_label(charset.as_bytes()) {
Some(encoding) => encoding
.decode_without_bom_handling_and_without_replacement(bytes)
.ok_or_else(|| std::io::ErrorKind::InvalidData.into()),
Some(encoding) => Ok(encoding.decode_without_bom_handling(bytes).0),
None => Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("Unsupported charset: {charset}"),
Expand Down Expand Up @@ -109,8 +107,6 @@ mod test {
fn test_decoding_invalid_utf8() {
let test_data = b"\xFE\xFE\xFF\xFF".to_vec();
let result = convert_to_utf8(&test_data, "utf-8");
assert!(result.is_err());
let err = result.expect_err("Err expected");
assert!(err.kind() == ErrorKind::InvalidData);
assert!(result.is_ok());
}
}

0 comments on commit 8854453

Please sign in to comment.