From 3fd43d343aa7fee8a4cabf5484e8cc5f5033a6f9 Mon Sep 17 00:00:00 2001 From: bushixuanqi <2208877960@qq.com> Date: Mon, 12 Jul 2021 00:41:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=93=BE=E6=8E=A5=E5=88=86?= =?UTF-8?q?=E5=89=B2=E8=A7=84=E5=88=99=EF=BC=8C=E9=81=BF=E5=85=8D=20,{c?= =?UTF-8?q?=E5=8F=82=E6=95=B0}=20=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E4=B8=AD=E4=B9=9F=E5=AD=98=E5=9C=A8=20,{=20=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=A7=84=E5=88=99=E5=88=87=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复这种页数列表写法中,js部分内含 < 或 > 就会切割错误的问题 简化图片格式化操作 --- .../io/legado/app/data/entities/BookChapter.kt | 9 ++++----- .../io/legado/app/model/analyzeRule/AnalyzeRule.kt | 3 ++- .../io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 14 +++++++------- .../main/java/io/legado/app/utils/HtmlFormatter.kt | 13 ++++++------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 9489f1723..a9cef2da8 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -5,7 +5,6 @@ import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.Ignore import androidx.room.Index -import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.GSON import io.legado.app.utils.MD5Utils import io.legado.app.utils.fromJsonObject @@ -62,10 +61,10 @@ data class BookChapter( return false } - fun getAbsoluteURL() = if(url.indexOf(',') != -1) { - val absoluteUrl = url.split(AnalyzeUrl.splitUrlRegex, 1)[0] - "${absoluteUrl},${url.substring(absoluteUrl.length)}" - } else url + fun getAbsoluteURL():String{ + val pos = url.indexOf(',') + return if (pos == -1) url else "${url.substring(0,pos).trim{it < '!'}},${url.substring(pos + 1).trim{it < '!'}}" + } fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title)) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 3be90112a..049d69a24 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -65,7 +65,8 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { fun setRedirectUrl(url: String): URL? { kotlin.runCatching { - redirectUrl = URL(url.split(AnalyzeUrl.splitUrlRegex, 1)[0]) + val pos = url.indexOf(',') + redirectUrl = URL( if(pos == -1) url else url.substring(0,pos).trim{ it < '!'} ) } return redirectUrl } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 16a88b941..9848c2b44 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -39,7 +39,6 @@ class AnalyzeUrl( headerMapF: Map? = null ) : JsExtensions { companion object { - val splitUrlRegex = Regex("\\s*,\\s*(?=\\{)") private val pagePattern = Pattern.compile("<(.*?)>") } @@ -56,7 +55,8 @@ class AnalyzeUrl( private var retry: Int = 0 init { - baseUrl = baseUrl.split(splitUrlRegex, 1)[0] + val pos = baseUrl.indexOf(',') + if(pos != -1)baseUrl = baseUrl.substring(0,pos).trim { it < '!' } headerMapF?.let { headerMap.putAll(it) if (it.containsKey("proxy")) { @@ -158,9 +158,9 @@ class AnalyzeUrl( */ private fun initUrl() { - val hasQuery = ruleUrl.indexOf(',') != -1 + var pos = ruleUrl.indexOf(',') - urlHasQuery = if(hasQuery) ruleUrl.split(splitUrlRegex, 1)[0] else ruleUrl + urlHasQuery = if(pos == -1) ruleUrl else ruleUrl.substring(0,pos).trim{ it < '!'} url = NetworkUtils.getAbsoluteURL(baseUrl,urlHasQuery ) @@ -168,8 +168,8 @@ class AnalyzeUrl( baseUrl = it } - if(hasQuery) { - GSON.fromJsonObject(ruleUrl.substring(urlHasQuery.length))?.let { option -> + if(pos != -1 ) { + GSON.fromJsonObject(ruleUrl.substring(pos + 1).trim{ it < '!'})?.let { option -> option.method?.let { if (it.equals("POST", true)) method = RequestMethod.POST @@ -207,7 +207,7 @@ class AnalyzeUrl( when (method) { RequestMethod.GET -> { if (!useWebView) { - val pos = url.indexOf('?') + pos = url.indexOf('?') if(pos != -1) { analyzeFields(url.substring(pos + 1)) url = url.substring(0,pos) diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt index 2b89f4f20..aa2f0f79a 100644 --- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt +++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt @@ -1,7 +1,6 @@ package io.legado.app.utils import io.legado.app.constant.AppPattern.imgPattern -import io.legado.app.model.analyzeRule.AnalyzeUrl import java.net.URL import java.util.regex.Pattern @@ -37,14 +36,14 @@ object HtmlFormatter { var url = matcher.group(1)!! val param:String + val pos = url.indexOf(',') - url = NetworkUtils.getAbsoluteURL(redirectUrl, if(url.indexOf(',') != -1) { - val absoluteUrl = url.split(AnalyzeUrl.splitUrlRegex, 1)[0] - param = url.substring(absoluteUrl.length) - absoluteUrl - } else { + url = NetworkUtils.getAbsoluteURL(redirectUrl, if(pos == -1){ param = "" - url + url.trim{ it <'!'} + } else { + param = url.substring(pos+1).trim{ it <'!'} + url.substring(0,pos).trim{ it <'!'} }) sb.append(keepImgHtml.substring(appendPos, matcher.start()))