From 99835dfc170de97f57f4fbf1f1cdce236613a5d3 Mon Sep 17 00:00:00 2001
From: Xwite <1797350009@qq.com>
Date: Wed, 1 Jun 2022 17:25:15 +0800
Subject: [PATCH 1/4] fix(epub): reset ReadConfig.useReplaceRule to false
fix #1831
---
app/src/main/java/io/legado/app/data/entities/Book.kt | 3 ++-
app/src/main/java/io/legado/app/model/localBook/EpubFile.kt | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt
index 449d6eacc..d5ff08514 100644
--- a/app/src/main/java/io/legado/app/data/entities/Book.kt
+++ b/app/src/main/java/io/legado/app/data/entities/Book.kt
@@ -202,7 +202,8 @@ data class Book(
if (useReplaceRule != null) {
return useReplaceRule
}
- if (type == BookType.image) {
+ //图片类书源 epub本地 默认关闭净化
+ if (type == BookType.image || isEpub()) {
return false
}
return AppConfig.replaceEnableDefault
diff --git a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
index 5d4d36e96..b12e0726e 100644
--- a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
+++ b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
@@ -33,7 +33,7 @@ class EpubFile(var book: Book) {
if (eFile == null || eFile?.book?.bookUrl != book.bookUrl) {
eFile = EpubFile(book)
//对于Epub文件默认不启用替换
- book.setUseReplaceRule(false)
+ //io.legado.app.data.entities.Book getUseReplaceRule
return eFile!!
}
eFile?.book = book
From 2f4f7f46b74c763d9f1a2405121da2151fa66767 Mon Sep 17 00:00:00 2001
From: Xwite <1797350009@qq.com>
Date: Wed, 1 Jun 2022 17:43:03 +0800
Subject: [PATCH 2/4] feat(ImageProvider): toast when image url is empty
---
.../app/ui/book/read/page/provider/ImageProvider.kt | 9 ++++++---
app/src/main/res/values-es-rES/strings.xml | 2 ++
app/src/main/res/values-ja-rJP/strings.xml | 2 ++
app/src/main/res/values-pt-rBR/strings.xml | 2 ++
app/src/main/res/values-zh-rHK/strings.xml | 2 ++
app/src/main/res/values-zh-rTW/strings.xml | 2 ++
app/src/main/res/values-zh/strings.xml | 2 ++
app/src/main/res/values/strings.xml | 2 ++
8 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
index 549372c51..bf9954da3 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
@@ -13,8 +13,7 @@ import io.legado.app.help.BookHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.localBook.EpubFile
-import io.legado.app.utils.BitmapUtils
-import io.legado.app.utils.FileUtils
+import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import splitties.init.appCtx
@@ -113,6 +112,10 @@ object ImageProvider {
width: Int,
height: Int? = null
): Bitmap {
+ //src为空白时 可能被净化替换掉了 或者规则失效
+ if (book.getUseReplaceRule() && src.isBlank()) {
+ appCtx.toastOnUi(R.string.error_image_url_empty)
+ }
val vFile = BookHelp.getImage(book, src)
if (!vFile.exists()) return errorBitmap
//epub文件提供图片链接是相对链接,同时阅读多个epub文件,缓存命中错误
@@ -122,7 +125,7 @@ object ImageProvider {
@Suppress("BlockingMethodInNonBlockingContext")
return kotlin.runCatching {
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height)
- ?: throw NoStackTraceException("解析图片失败")
+ ?: throw NoStackTraceException(appCtx.getString(R.string.error_decode_bitmap))
bitmapLruCache.put(vFile.absolutePath, bitmap)
bitmap
}.onFailure {
diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml
index 6e95b867d..5827eba82 100644
--- a/app/src/main/res/values-es-rES/strings.xml
+++ b/app/src/main/res/values-es-rES/strings.xml
@@ -993,4 +993,6 @@
bitmap cache size
Export Picture Files
+ Fail to decode bitmap
+ Image url is empty, check replacement rules
diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml
index aad299b97..88570cfdc 100644
--- a/app/src/main/res/values-ja-rJP/strings.xml
+++ b/app/src/main/res/values-ja-rJP/strings.xml
@@ -996,4 +996,6 @@
bitmap cache size
Export Picture Files
+ Fail to decode bitmap
+ Image url is empty, check replacement rules
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index 6aa240a76..ee55c893a 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -996,4 +996,6 @@
bitmap cache size
Export Picture Files
+ Fail to decode bitmap
+ Image url is empty, check replacement rules
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 32b479fb6..22c20f729 100644
--- a/app/src/main/res/values-zh-rHK/strings.xml
+++ b/app/src/main/res/values-zh-rHK/strings.xml
@@ -993,4 +993,6 @@
图片绘制缓存
TXT导出图片
+ 图片解码失败
+ 图片链接为空,检查替换净化规则
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index bb8b1d278..963cff29e 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -995,4 +995,6 @@
圖片繪製快取
TXT匯出圖片
+ 图片解码失败
+ 图片链接为空,检查替换净化规则
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 216791d7e..a4727df79 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -995,4 +995,6 @@
图片绘制缓存
TXT导出图片
+ 图片解码失败
+ 图片链接为空,检查替换净化规则
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f94211986..d6905d954 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -996,4 +996,6 @@
bitmap cache size
Export Picture Files
+ Fail to decode bitmap
+ Image url is empty, check replacement rules
From 6098260f4533f1e22b1e217292c15660befa3508 Mon Sep 17 00:00:00 2001
From: Xwite <1797350009@qq.com>
Date: Wed, 1 Jun 2022 18:27:34 +0800
Subject: [PATCH 3/4] feat(ImageProvider): disable replace when detect empty
image url
---
.../io/legado/app/ui/book/read/page/provider/ImageProvider.kt | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
index bf9954da3..19dd436f0 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
@@ -114,6 +114,7 @@ object ImageProvider {
): Bitmap {
//src为空白时 可能被净化替换掉了 或者规则失效
if (book.getUseReplaceRule() && src.isBlank()) {
+ book.setUseReplaceRule(false)
appCtx.toastOnUi(R.string.error_image_url_empty)
}
val vFile = BookHelp.getImage(book, src)
From 23d26172a4128e92e778708a480231f162e642d8 Mon Sep 17 00:00:00 2001
From: Xwite <1797350009@qq.com>
Date: Wed, 1 Jun 2022 19:47:39 +0800
Subject: [PATCH 4/4] fix: check suffix characters
---
app/src/main/java/io/legado/app/help/BookHelp.kt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt
index 7e68c778c..0d607a5f1 100644
--- a/app/src/main/java/io/legado/app/help/BookHelp.kt
+++ b/app/src/main/java/io/legado/app/help/BookHelp.kt
@@ -144,7 +144,9 @@ object BookHelp {
fun getImageSuffix(src: String): String {
var suffix = src.substringAfterLast(".").substringBefore(",")
- if (suffix.length > 5) {
+ //检查截取的后缀字符是否合法 [a-zA-Z0-9]
+ val fileSuffixRegex = Regex("^[a-z0-9]+$", RegexOption.IGNORE_CASE)
+ if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) {
suffix = "jpg"
}
return suffix