修复null崩溃bug

pull/349/head
gedoor 4 years ago
parent 8f7369d690
commit fb97833526
  1. 2
      app/src/main/java/io/legado/app/constant/AppPattern.kt
  2. 22
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  3. 3
      app/src/main/java/io/legado/app/service/help/ReadBook.kt

@ -6,7 +6,7 @@ object AppPattern {
val JS_PATTERN: Pattern =
Pattern.compile("(<js>[\\w\\W]*?</js>|@js:[\\w\\W]*$)", Pattern.CASE_INSENSITIVE)
val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}")
val imgPattern =
val imgPattern: Pattern =
Pattern.compile("<img .*?src.*?=.*?\"(.*?(?:,\\{.*\\})?)\".*?>", Pattern.CASE_INSENSITIVE)
val nameRegex = Regex("\\s+作\\s*者.*")

@ -40,7 +40,7 @@ class AnalyzeUrl(
headerMapF: Map<String, String>? = null,
baseUrl: String? = null,
book: BaseBook? = null,
var useWebView: Boolean = false
var useWebView: Boolean = false,
) : JsExtensions {
companion object {
private val pagePattern = Pattern.compile("<(.*?)>")
@ -68,7 +68,7 @@ class AnalyzeUrl(
headerMapF?.let {
headerMap.putAll(it)
if (it.containsKey("proxy")) {
proxy = it["proxy"];
proxy = it["proxy"]
headerMap.remove("proxy")
}
}
@ -84,7 +84,7 @@ class AnalyzeUrl(
page: Int?,
speakText: String?,
speakSpeed: Int?,
book: BaseBook?
book: BaseBook?,
) {
val ruleList = arrayListOf<String>()
var start = 0
@ -133,7 +133,7 @@ class AnalyzeUrl(
page: Int?,
speakText: String?,
speakSpeed: Int?,
book: BaseBook?
book: BaseBook?,
) {
//page
page?.let {
@ -161,7 +161,9 @@ class AnalyzeUrl(
simpleBindings["book"] = book
val expMatcher = EXP_PATTERN.matcher(ruleUrl)
while (expMatcher.find()) {
jsEval = SCRIPT_ENGINE.eval(expMatcher.group(1), simpleBindings)
jsEval = expMatcher.group(1)?.let {
SCRIPT_ENGINE.eval(it, simpleBindings)
} ?: ""
if (jsEval is String) {
expMatcher.appendReplacement(sb, jsEval)
} else if (jsEval is Double && jsEval % 1.0 == 0.0) {
@ -272,7 +274,7 @@ class AnalyzeUrl(
key: String?,
speakText: String?,
speakSpeed: Int?,
book: BaseBook?
book: BaseBook?,
): Any {
val bindings = SimpleBindings()
bindings["java"] = this
@ -317,7 +319,7 @@ class AnalyzeUrl(
suspend fun getResponseAwait(
tag: String,
jsStr: String? = null,
sourceRegex: String? = null
sourceRegex: String? = null,
): Res {
if (useWebView) {
val params = AjaxWebView.AjaxParams(url)
@ -432,9 +434,9 @@ class AnalyzeUrl(
@Throws(Exception::class)
fun getGlideUrl(): Any? {
var glideUrl: Any = urlHasQuery
if(headerMap.isNotEmpty()) {
if (headerMap.isNotEmpty()) {
val headers = LazyHeaders.Builder()
headerMap.forEach {(key, value) ->
headerMap.forEach { (key, value) ->
headers.addHeader(key, value)
}
glideUrl = GlideUrl(urlHasQuery, headers.build())
@ -447,7 +449,7 @@ class AnalyzeUrl(
val charset: String?,
val webView: Any?,
val headers: Any?,
val body: Any?
val body: Any?,
)
}

@ -22,6 +22,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jetbrains.anko.getStackTraceString
import org.jetbrains.anko.toast
@ -370,7 +371,7 @@ object ReadBook {
}
}.onError {
it.printStackTrace()
App.INSTANCE.toast(it.localizedMessage ?: "ChapterProvider ERROR")
App.INSTANCE.toast("ChapterProvider ERROR:\n${it.getStackTraceString()}")
}
}

Loading…
Cancel
Save