diff options
author | Lukáš Tyrychtr <ltyrycht@redhat.com> | 2023-03-23 10:48:59 +0100 |
---|---|---|
committer | Lukáš Tyrychtr <ltyrycht@redhat.com> | 2023-03-23 10:59:23 +0100 |
commit | 481da345d450c8ef764d53c38c2e641f8fe0fec1 (patch) | |
tree | a0d5b18352856326e54c88cd72e2121437c4ed37 | |
parent | 7abc17455a12dc6e189e1438376ff1fdbd1dbc5f (diff) | |
download | librsvg-481da345d450c8ef764d53c38c2e641f8fe0fec1.tar.gz |
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: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/818>
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/xml/mod.rs | 11 |
3 files changed, 16 insertions, 8 deletions
@@ -633,6 +633,15 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1110,7 +1119,7 @@ dependencies = [ "criterion", "cssparser", "data-url", - "encoding", + "encoding_rs", "float-cmp", "gdk-pixbuf", "gio", @@ -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); |