From 257bfe843ee4345420b4f01cb26001f0ff3b0761 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 26 Jul 2026 22:45:05 +0800 Subject: [PATCH] Add missing `nbsp` and `times` entities --- app/src/main/rust/src/parser/config.rs | 2 +- app/src/main/rust/src/parser/detail.rs | 2 +- app/src/main/rust/src/parser/fav.rs | 2 +- app/src/main/rust/src/parser/list.rs | 2 +- app/src/main/rust/src/parser/profile.rs | 2 +- app/src/main/rust/src/parser/torrent.rs | 2 +- app/src/main/rust/src/parser/utils.rs | 16 ++++++++++++++++ .../kotlin/com/ehviewer/core/util/StringUtils.kt | 4 +++- 8 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/src/main/rust/src/parser/config.rs b/app/src/main/rust/src/parser/config.rs index 454267d5d..2cb8eaf63 100644 --- a/app/src/main/rust/src/parser/config.rs +++ b/app/src/main/rust/src/parser/config.rs @@ -1,5 +1,5 @@ +use crate::parser::utils::unescape; use crate::regex; -use quick_xml::escape::unescape; pub fn parse_fav_cat(html: &str) -> Vec { regex!(" i32 { s.replace(",", "").parse().unwrap_or(default) } + +pub fn unescape(raw: &str) -> Result, EscapeError> { + unescape_with(raw, resolve_predefined_entity) +} + +#[inline] +const fn resolve_predefined_entity(entity: &str) -> Option<&'static str> { + match entity.as_bytes() { + b"nbsp" => Some(" "), + b"times" => Some("×"), + _ => resolve_xml_entity(entity), + } +} diff --git a/core/common/src/commonMain/kotlin/com/ehviewer/core/util/StringUtils.kt b/core/common/src/commonMain/kotlin/com/ehviewer/core/util/StringUtils.kt index d62601140..3ecfda77c 100644 --- a/core/common/src/commonMain/kotlin/com/ehviewer/core/util/StringUtils.kt +++ b/core/common/src/commonMain/kotlin/com/ehviewer/core/util/StringUtils.kt @@ -1,12 +1,14 @@ package com.ehviewer.core.util -private val EntityRegex = "&(?:amp|lt|gt|quot|#039);".toRegex() +private val EntityRegex = "&(?:amp|lt|gt|quot|#039|nbsp|times);".toRegex() private val EntityMap = mapOf( "&" to "&", "<" to "<", ">" to ">", """ to "\"", "'" to "'", // HTML uses ' instead of ' + " " to " ", + "×" to "×", ) fun String.unescapeXml() = replace(EntityRegex) { EntityMap[it.value]!! }