修复规则解析bug

pull/395/head
gedoor 4 years ago
parent 6b6a39e07d
commit 487524182a
  1. 17
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@ -406,6 +406,9 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
internal val putMap = HashMap<String, String>() internal val putMap = HashMap<String, String>()
private val ruleParam = ArrayList<String>() private val ruleParam = ArrayList<String>()
private val ruleType = ArrayList<Int>() private val ruleType = ArrayList<Int>()
private val getRuleType = -2
private val jsRuleType = -1
private val defaultRuleType = 0
init { init {
this.mode = mainMode this.mode = mainMode
@ -461,11 +464,11 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
tmp = evalMatcher.group() tmp = evalMatcher.group()
when { when {
tmp.startsWith("@get:", true) -> { tmp.startsWith("@get:", true) -> {
ruleType.add(-2) ruleType.add(getRuleType)
ruleParam.add(tmp.substring(6, tmp.lastIndex)) ruleParam.add(tmp.substring(6, tmp.lastIndex))
} }
tmp.startsWith("{{") -> { tmp.startsWith("{{") -> {
ruleType.add(-1) ruleType.add(jsRuleType)
ruleParam.add(tmp.substring(2, tmp.length - 2)) ruleParam.add(tmp.substring(2, tmp.length - 2))
} }
else -> { else -> {
@ -494,7 +497,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
} }
if (regexMatcher.start() > start) { if (regexMatcher.start() > start) {
tmp = ruleStr.substring(start, regexMatcher.start()) tmp = ruleStr.substring(start, regexMatcher.start())
ruleType.add(0) ruleType.add(defaultRuleType)
ruleParam.add(tmp) ruleParam.add(tmp)
} }
tmp = regexMatcher.group() tmp = regexMatcher.group()
@ -504,7 +507,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
} }
if (ruleStr.length > start) { if (ruleStr.length > start) {
tmp = ruleStr.substring(start) tmp = ruleStr.substring(start)
ruleType.add(0) ruleType.add(defaultRuleType)
ruleParam.add(tmp) ruleParam.add(tmp)
} }
} }
@ -519,7 +522,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
while (index-- > 0) { while (index-- > 0) {
val regType = ruleType[index] val regType = ruleType[index]
when { when {
regType > 0 -> { regType > defaultRuleType -> {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
val resultList = result as? List<String?> val resultList = result as? List<String?>
if (resultList != null) { if (resultList != null) {
@ -532,7 +535,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
infoVal.insert(0, ruleParam[index]) infoVal.insert(0, ruleParam[index])
} }
} }
regType == -1 -> { regType == jsRuleType -> {
if (isRule(ruleParam[index])) { if (isRule(ruleParam[index])) {
getString(arrayListOf(SourceRule(ruleParam[index]))).let { getString(arrayListOf(SourceRule(ruleParam[index]))).let {
infoVal.insert(0, it) infoVal.insert(0, it)
@ -550,7 +553,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
} }
} }
} }
regType == -2 -> { regType == getRuleType -> {
infoVal.insert(0, get(ruleParam[index])) infoVal.insert(0, get(ruleParam[index]))
} }
else -> infoVal.insert(0, ruleParam[index]) else -> infoVal.insert(0, ruleParam[index])

Loading…
Cancel
Save