优化链接分割规则,避免 ,{c参数} 的字符串中也存在 ,{ ,导致规则切错

修复<str0,str2,...{{js}}>这种页数列表写法中,js部分内含 < 或 > 就会切割错误的问题

简化图片格式化操作
pull/1118/head
bushixuanqi 3 years ago
parent 7bb6a63571
commit 3fd43d343a
  1. 9
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  2. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  3. 14
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  4. 13
      app/src/main/java/io/legado/app/utils/HtmlFormatter.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))

@ -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
}

@ -39,7 +39,6 @@ class AnalyzeUrl(
headerMapF: Map<String, String>? = 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<UrlOption>(ruleUrl.substring(urlHasQuery.length))?.let { option ->
if(pos != -1 ) {
GSON.fromJsonObject<UrlOption>(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)

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

Loading…
Cancel
Save