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()))