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

@ -40,7 +40,7 @@ class AnalyzeUrl(
headerMapF: Map<String, String>? = null, headerMapF: Map<String, String>? = null,
baseUrl: String? = null, baseUrl: String? = null,
book: BaseBook? = null, book: BaseBook? = null,
var useWebView: Boolean = false var useWebView: Boolean = false,
) : JsExtensions { ) : JsExtensions {
companion object { companion object {
private val pagePattern = Pattern.compile("<(.*?)>") private val pagePattern = Pattern.compile("<(.*?)>")
@ -68,7 +68,7 @@ class AnalyzeUrl(
headerMapF?.let { headerMapF?.let {
headerMap.putAll(it) headerMap.putAll(it)
if (it.containsKey("proxy")) { if (it.containsKey("proxy")) {
proxy = it["proxy"]; proxy = it["proxy"]
headerMap.remove("proxy") headerMap.remove("proxy")
} }
} }
@ -84,7 +84,7 @@ class AnalyzeUrl(
page: Int?, page: Int?,
speakText: String?, speakText: String?,
speakSpeed: Int?, speakSpeed: Int?,
book: BaseBook? book: BaseBook?,
) { ) {
val ruleList = arrayListOf<String>() val ruleList = arrayListOf<String>()
var start = 0 var start = 0
@ -133,7 +133,7 @@ class AnalyzeUrl(
page: Int?, page: Int?,
speakText: String?, speakText: String?,
speakSpeed: Int?, speakSpeed: Int?,
book: BaseBook? book: BaseBook?,
) { ) {
//page //page
page?.let { page?.let {
@ -161,7 +161,9 @@ class AnalyzeUrl(
simpleBindings["book"] = book simpleBindings["book"] = book
val expMatcher = EXP_PATTERN.matcher(ruleUrl) val expMatcher = EXP_PATTERN.matcher(ruleUrl)
while (expMatcher.find()) { 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) { if (jsEval is String) {
expMatcher.appendReplacement(sb, jsEval) expMatcher.appendReplacement(sb, jsEval)
} else if (jsEval is Double && jsEval % 1.0 == 0.0) { } else if (jsEval is Double && jsEval % 1.0 == 0.0) {
@ -272,7 +274,7 @@ class AnalyzeUrl(
key: String?, key: String?,
speakText: String?, speakText: String?,
speakSpeed: Int?, speakSpeed: Int?,
book: BaseBook? book: BaseBook?,
): Any { ): Any {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = this bindings["java"] = this
@ -317,7 +319,7 @@ class AnalyzeUrl(
suspend fun getResponseAwait( suspend fun getResponseAwait(
tag: String, tag: String,
jsStr: String? = null, jsStr: String? = null,
sourceRegex: String? = null sourceRegex: String? = null,
): Res { ): Res {
if (useWebView) { if (useWebView) {
val params = AjaxWebView.AjaxParams(url) val params = AjaxWebView.AjaxParams(url)
@ -432,9 +434,9 @@ class AnalyzeUrl(
@Throws(Exception::class) @Throws(Exception::class)
fun getGlideUrl(): Any? { fun getGlideUrl(): Any? {
var glideUrl: Any = urlHasQuery var glideUrl: Any = urlHasQuery
if(headerMap.isNotEmpty()) { if (headerMap.isNotEmpty()) {
val headers = LazyHeaders.Builder() val headers = LazyHeaders.Builder()
headerMap.forEach {(key, value) -> headerMap.forEach { (key, value) ->
headers.addHeader(key, value) headers.addHeader(key, value)
} }
glideUrl = GlideUrl(urlHasQuery, headers.build()) glideUrl = GlideUrl(urlHasQuery, headers.build())
@ -447,7 +449,7 @@ class AnalyzeUrl(
val charset: String?, val charset: String?,
val webView: Any?, val webView: Any?,
val headers: 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.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.getStackTraceString
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
@ -370,7 +371,7 @@ object ReadBook {
} }
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
App.INSTANCE.toast(it.localizedMessage ?: "ChapterProvider ERROR") App.INSTANCE.toast("ChapterProvider ERROR:\n${it.getStackTraceString()}")
} }
} }

Loading…
Cancel
Save