Horis 2 лет назад
Родитель
Сommit
ad08fa7b47
1 измененных файлов с 5 добавлено и 2 удалено
  1. 5 2
      app/src/main/java/io/legado/app/utils/RegexExtensions.kt

+ 5 - 2
app/src/main/java/io/legado/app/utils/RegexExtensions.kt

@@ -10,6 +10,7 @@ import kotlinx.coroutines.Dispatchers.IO
 import kotlinx.coroutines.runBlocking
 import kotlinx.coroutines.suspendCancellableCoroutine
 import splitties.init.appCtx
+import java.util.regex.Matcher
 import kotlin.coroutines.resume
 import kotlin.coroutines.resumeWithException
 
@@ -36,7 +37,8 @@ fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): Stri
                                 bindings["result"] = matcher.group()
                                 eval(replacement1, bindings)
                             }.toString()
-                            matcher.appendReplacement(stringBuffer, jsResult)
+                            val quotedResult = Matcher.quoteReplacement(jsResult)
+                            matcher.appendReplacement(stringBuffer, quotedResult)
                         } else {
                             matcher.appendReplacement(stringBuffer, replacement1)
                         }
@@ -49,7 +51,8 @@ fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): Stri
             }
             handler.postDelayed(timeout) {
                 if (coroutine.isActive) {
-                    val timeoutMsg = "替换超时,3秒后还未结束将重启应用\n替换规则$regex\n替换内容:${this}"
+                    val timeoutMsg =
+                        "替换超时,3秒后还未结束将重启应用\n替换规则$regex\n替换内容:$charSequence"
                     val exception = RegexTimeoutException(timeoutMsg)
                     block.cancel(exception)
                     appCtx.longToastOnUi(timeoutMsg)