Mangabz: Fix StringIndexOutOfBoundsException (#9710)

* Mangabz: Fix StringIndexOutOfBoundsException

StringIndexOutOfBoundsException happens when description is the same as title

* fix description

* remove some lazys since JVM guarantees initialization only when calling this file

---------

Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com>
This commit is contained in:
tanaka-shizuku3 2025-07-20 01:30:23 +08:00 committed by Draff
parent b09647744c
commit 1f8bb317b6
Signed by: Draff
GPG Key ID: E8A89F3211677653
3 changed files with 14 additions and 17 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Mangabz'
extClass = '.Mangabz'
extVersionCode = 11
extVersionCode = 12
isNsfw = false
}

View File

@ -29,10 +29,10 @@ fun parseDateInternal(source: String): Long {
return fullDateFormat.parse(source)!!.time
}
private val recentRegex by lazy { Regex("""[今昨前]天 \d{2}:\d{2}""") }
private val timeFormat by lazy { cstFormat("yyyy-MM-dd hh:mm") }
private val shortDateFormat by lazy { cstFormat("yyyy MM月dd") }
private val fullDateFormat by lazy { cstFormat("yyyy-MM-dd") }
private val recentRegex = Regex("""[今昨前]天 \d{2}:\d{2}""")
private val timeFormat = cstFormat("yyyy-MM-dd hh:mm")
private val shortDateFormat = cstFormat("yyyy MM月dd")
private val fullDateFormat = cstFormat("yyyy-MM-dd")
private fun cstFormat(pattern: String) =
SimpleDateFormat(pattern, Locale.ENGLISH).apply { timeZone = TimeZone.getTimeZone("GMT+8") }

View File

@ -26,7 +26,7 @@ import rx.Observable
class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
private val _baseUrl: String
override val baseUrl: String
override val client: OkHttpClient
private val urlSuffix: String
@ -34,7 +34,10 @@ class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
init {
val preferences = getPreferences()
val mirror = preferences.mirror
_baseUrl = "https://" + mirror.domain
baseUrl = when (System.getenv("CI")) {
"true" -> MIRRORS.joinToString("#, ") { "https://" + it.domain }
else -> "https://" + mirror.domain
}
urlSuffix = mirror.urlSuffix
val cookieInterceptor = CookieInterceptor(mirror.domain, mirror.langCookie to preferences.lang)
@ -44,14 +47,8 @@ class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
.build()
}
private val isCi = System.getenv("CI") == "true"
override val baseUrl get() = when {
isCi -> MIRRORS.joinToString("#, ") { "https://" + it.domain }
else -> _baseUrl
}
override fun headersBuilder() = Headers.Builder()
.add("Referer", _baseUrl)
.add("Referer", baseUrl)
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0")
private fun SManga.stripMirror() = apply {
@ -95,10 +92,10 @@ class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
override fun parseDescription(element: Element, title: String, details: Elements): String {
val text = element.ownText()
val start = if (text.startsWith(title)) title.length + 4 else 0
val start = text.removePrefix("${title}漫画 ").removePrefix("${title}漫畫 ")
val collapsed = element.selectFirst(Evaluator.Tag("span"))?.ownText()
?: return text.substring(start)
return buildString { append(text, start, text.length - 1).append(collapsed) }
?: return start
return start + collapsed
}
override fun chapterListRequest(manga: SManga) = GET(baseUrl + manga.url.toMirror(), headers)