From 481da345d450c8ef764d53c38c2e641f8fe0fec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tyrychtr?= Date: Thu, 23 Mar 2023 10:48:59 +0100 Subject: xml: Replace unmaitained encoding crate by encoding_rs This replaces unmaintained encoding crate by encoding_rs. The indirect reference through lopdf still remains, but this is a start. This fixes the direct part of #949. Part-of: --- Cargo.lock | 11 ++++++++++- Cargo.toml | 2 +- src/xml/mod.rs | 11 +++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae1bbbe4..d962869f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -632,6 +632,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if", +] + [[package]] name = "errno" version = "0.2.8" @@ -1110,7 +1119,7 @@ dependencies = [ "criterion", "cssparser", "data-url", - "encoding", + "encoding_rs", "float-cmp", "gdk-pixbuf", "gio", diff --git a/Cargo.toml b/Cargo.toml index 0272d90f..d9e066d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ clap = { version = "4.0.17", features = ["cargo", "derive"] } # rsvg-convert clap_complete = "4.0.5" # rsvg-convert cssparser = "0.29.0" data-url = "0.2.0" -encoding = "0.2.33" +encoding_rs = "0.8.32" float-cmp = "0.9.0" gdk-pixbuf = "0.17" gio = "0.17" diff --git a/src/xml/mod.rs b/src/xml/mod.rs index 4f544176..0c75f8a8 100644 --- a/src/xml/mod.rs +++ b/src/xml/mod.rs @@ -1,7 +1,6 @@ //! The main XML parser. -use encoding::label::encoding_from_whatwg_label; -use encoding::DecoderTrap; +use encoding_rs::Encoding; use gio::{ prelude::BufferedInputStreamExt, BufferedInputStream, Cancellable, ConverterInputStream, InputStream, ZlibCompressorFormat, ZlibDecompressor, @@ -585,14 +584,14 @@ impl XmlState { let encoding = encoding.unwrap_or("utf-8"); - let encoder = encoding_from_whatwg_label(encoding).ok_or_else(|| { + let encoder = Encoding::for_label_no_replacement(encoding.as_bytes()).ok_or_else(|| { AcquireError::FatalError(format!("unknown encoding \"{encoding}\" for \"{aurl}\"")) })?; let utf8_data = encoder - .decode(&binary.data, DecoderTrap::Strict) - .map_err(|e| { - AcquireError::FatalError(format!("could not convert contents of \"{aurl}\" from character encoding \"{encoding}\": {e}")) + .decode_without_bom_handling_and_without_replacement(&binary.data) + .ok_or_else(|| { + AcquireError::FatalError(format!("could not convert contents of \"{aurl}\" from character encoding \"{encoding}\"")) })?; self.element_creation_characters(&utf8_data); -- cgit v1.2.1