diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt index c8d5bb928..a3cf9f022 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt @@ -61,6 +61,7 @@ import java.nio.ByteBuffer import kotlin.math.ceil import kotlinx.coroutines.CancellationException import kotlinx.coroutines.delay +import kotlinx.serialization.SerializationException import kotlinx.serialization.json.add import kotlinx.serialization.json.addJsonArray import kotlinx.serialization.json.put @@ -106,7 +107,7 @@ private fun rethrowExactly(code: Int, body: String, e: Throwable): Nothing { throw StatusCodeException(code) } - if (e is ParseException) { + if (e is ParseException || e is SerializationException) { if ("<" !in body) { throw EhException(body) } else { @@ -142,6 +143,11 @@ suspend fun fetchCompat( cronetRequest(url, referer, origin) { reqBody?.let { withRequestBody(it) } }.execute { + @Suppress("NewApi") + val code = it.httpStatusCode + if (code >= 400) { + throw StatusCodeException(code) + } httpContentPool.useInstance { buffer -> awaitBodyFully(buffer) buffer.flip() diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryListParser.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryListParser.kt index 4aa907c4d..6ff0167a9 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryListParser.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryListParser.kt @@ -16,6 +16,9 @@ object GalleryListParser { parseGalleryInfoList(body) }.onFailure { if (it is RuntimeException) { + if (it.message?.startsWith("Your IP address") == true) { + throw EhException(it.message) + } if (it.message == "No watched tags!") { throw EhException(R.string.gallery_list_empty_hit_subscription) } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt index 3b72b1633..fbdb67832 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt @@ -16,7 +16,6 @@ package com.hippo.ehviewer.util import android.os.Environment -import com.hippo.ehviewer.client.exception.ParseException import java.io.File import splitties.init.appCtx @@ -60,7 +59,7 @@ object AppConfig { return FileUtils.createTempFile(tempDir, null) } - fun saveParseErrorBody(e: ParseException, body: String) { + fun saveParseErrorBody(e: Throwable, body: String) { val dir = externalParseErrorDir ?: return File(dir, ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt").writer().use { it.write(e.message) diff --git a/app/src/main/rust/src/lib.rs b/app/src/main/rust/src/lib.rs index fbebc8ba5..95065a1be 100644 --- a/app/src/main/rust/src/lib.rs +++ b/app/src/main/rust/src/lib.rs @@ -33,6 +33,12 @@ macro_rules! regex { const EHGT_PREFIX: &str = "https://ehgt.org/"; const EX_PREFIX: &str = "https://s.exhentai.org/"; +fn check_html(str: &str) { + if !str.contains('<') { + panic!("{}", str) + } +} + fn get_vdom_first_element_by_class_name<'a>(dom: &'a VDom, name: &str) -> Option<&'a Node<'a>> { let handle = dom.get_elements_by_class_name(name).next()?; handle.get(dom.parser()) diff --git a/app/src/main/rust/src/parser/list.rs b/app/src/main/rust/src/parser/list.rs index a546fce25..49760784f 100644 --- a/app/src/main/rust/src/parser/list.rs +++ b/app/src/main/rust/src/parser/list.rs @@ -5,11 +5,11 @@ use jnix::jni::sys::{jint, jobject}; use jnix::jni::JNIEnv; use jnix::{IntoJava, JnixEnv}; use jnix_macros::IntoJava; -use parse_bytebuffer; use quick_xml::escape::unescape; use std::borrow::Cow; use std::ops::Index; use tl::{Node, Parser}; +use {check_html, parse_bytebuffer}; use {get_element_by_id, get_vdom_first_element_by_class_name}; use {get_first_element_by_class_name, query_childs_first_match_attr}; use {get_node_attr, get_node_handle_attr, regex}; @@ -205,6 +205,7 @@ pub fn parseGalleryInfoList( ) -> jobject { let mut env = JnixEnv { env }; parse_bytebuffer(&mut env, buffer, limit, |dom, parser, _, str| { + check_html(str); if str.contains("

You do not have any watched tags") { panic!("No watched tags!") }