Add missing nbsp and times entities
This commit is contained in:
1 parent
49eb3bc234
commit
257bfe843e
8 files changed
+25
-7
No files matched your search
@@ -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<String> {
|
||||
regex!("<input type=\"text\" name=\"favorite_\\d\" value=\"([^\"]+)\"")
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::parser::list::{BaseGalleryInfo, get_thumb_key, parse_token_and_gid, to_category_i32};
|
||||
use crate::parser::utils::unescape;
|
||||
use crate::{EhError, get_first_child, get_first_element_by_class_name, get_node_handle_attr};
|
||||
use crate::{get_tag_attr, get_vdom_first_element_by_class_name, regex};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use chrono::naive::NaiveDateTime;
|
||||
use quick_xml::escape::unescape;
|
||||
use serde::Serialize;
|
||||
use tl::{Bytes, Node, NodeHandle, Parser, VDom};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::parser::list::{GalleryListResult, parse_info_list};
|
||||
use crate::parser::utils::unescape;
|
||||
use anyhow::{Result, bail};
|
||||
use quick_xml::escape::unescape;
|
||||
use serde::Serialize;
|
||||
use tl::Parser;
|
||||
use tl::VDom;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::EhError;
|
||||
use crate::parser::utils::unescape;
|
||||
use crate::{EHGT_PREFIX, EX_PREFIX};
|
||||
use crate::{get_element_by_id, get_vdom_first_element_by_class_name};
|
||||
use crate::{get_first_element_by_class_name, query_childs_first_match_attr};
|
||||
use crate::{get_node_attr, get_node_handle_attr, regex};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use quick_xml::escape::unescape;
|
||||
use serde::Serialize;
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Index;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::parser::utils::unescape;
|
||||
use crate::{EhError, get_node_handle_attr, get_tag_attr, select_first};
|
||||
use anyhow::{Context, Result};
|
||||
use quick_xml::escape::unescape;
|
||||
use serde::Serialize;
|
||||
use tl::{Parser, VDom};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::parser::utils::unescape;
|
||||
use crate::regex;
|
||||
use anyhow::{Context, Result};
|
||||
use quick_xml::escape::unescape;
|
||||
use serde::Serialize;
|
||||
use tl::{Parser, VDom};
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
use quick_xml::escape::{EscapeError, resolve_xml_entity, unescape_with};
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub fn parse_int_lenient(s: &str, default: i32) -> i32 {
|
||||
s.replace(",", "").parse().unwrap_or(default)
|
||||
}
|
||||
|
||||
pub fn unescape(raw: &str) -> Result<Cow<'_, str>, 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),
|
||||
}
|
||||
}
|
||||
@@ -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]!! }
|
||||
|
||||
Reference in new issue
Block a user