Replace unmaintained encoding dep with maintained encoding_rs dep (#4694)

* Replace dependency on unmaintained encoding crate with dep on maintained encoding_rs crate

* Update lockfile

* Taplo format Cargo.toml

* Use better variable name

* Replace into_owned with into
pull/4690/head^2
SleeplessOne1917 1 month ago committed by GitHub
parent 7540b02723
commit 485b0f1a54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

678
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -25,7 +25,7 @@ full = [
"lemmy_db_views_moderator/full", "lemmy_db_views_moderator/full",
"lemmy_utils/full", "lemmy_utils/full",
"activitypub_federation", "activitypub_federation",
"encoding", "encoding_rs",
"reqwest-middleware", "reqwest-middleware",
"webpage", "webpage",
"ts-rs", "ts-rs",
@ -69,7 +69,7 @@ mime = { version = "0.3.17", optional = true }
webpage = { version = "1.6", default-features = false, features = [ webpage = { version = "1.6", default-features = false, features = [
"serde", "serde",
], optional = true } ], optional = true }
encoding = { version = "0.2.33", optional = true } encoding_rs = { version = "0.8.34", optional = true }
jsonwebtoken = { version = "8.3.0", optional = true } jsonwebtoken = { version = "8.3.0", optional = true }
# necessary for wasmt compilation # necessary for wasmt compilation
getrandom = { version = "0.2.14", features = ["js"] } getrandom = { version = "0.2.14", features = ["js"] }

@ -6,7 +6,7 @@ use crate::{
utils::{local_site_opt_to_sensitive, proxy_image_link, proxy_image_link_opt_apub}, utils::{local_site_opt_to_sensitive, proxy_image_link, proxy_image_link_opt_apub},
}; };
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use encoding::{all::encodings, DecoderTrap}; use encoding_rs::{Encoding, UTF_8};
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::DbUrl, newtypes::DbUrl,
source::{ source::{
@ -160,11 +160,9 @@ fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> LemmyResult<OpenGraph
// proper encoding. If the specified encoding cannot be found, fall back to the original UTF-8 // proper encoding. If the specified encoding cannot be found, fall back to the original UTF-8
// version. // version.
if let Some(charset) = page.meta.get("charset") { if let Some(charset) = page.meta.get("charset") {
if charset.to_lowercase() != "utf-8" { if charset != UTF_8.name() {
if let Some(encoding_ref) = encodings().iter().find(|e| e.name() == charset) { if let Some(encoding) = Encoding::for_label(charset.as_bytes()) {
if let Ok(html_with_encoding) = encoding_ref.decode(html_bytes, DecoderTrap::Replace) { page = HTML::from_string(encoding.decode(html_bytes).0.into(), None)?;
page = HTML::from_string(html_with_encoding, None)?;
}
} }
} }
} }

Loading…
Cancel
Save