From be93369a4ebdd167321fb96c54b4e9f81d5c2858 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 30 Jun 2019 22:10:57 +0800 Subject: [PATCH] up --- .../app/model/analyzeRule/AnalyzeUrl.kt | 13 +++------ .../main/java/io/legado/app/utils/Encoder.kt | 29 +++++++++++++++++++ app/src/main/res/layout/pop_keyboard_tool.xml | 24 +++++++++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/Encoder.kt diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index bdd0fb06a..1f72643c9 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -5,6 +5,7 @@ import android.text.TextUtils import androidx.annotation.Keep import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.Pattern.EXP_PATTERN +import io.legado.app.utils.Encoder import io.legado.app.utils.GSON import io.legado.app.utils.NetworkUtils import io.legado.app.utils.fromJsonObject @@ -119,6 +120,7 @@ class AnalyzeUrl( private fun initUrl() { val urlArray = ruleUrl.split(",\n*".toRegex(), 2) url = urlArray[0] + host = NetworkUtils.getBaseUrl(url) if (urlArray.size > 1) { val options = GSON.fromJsonObject>(urlArray[1]) options?.let { @@ -134,6 +136,7 @@ class AnalyzeUrl( } } + /** * 解析QueryMap */ @@ -151,7 +154,7 @@ class AnalyzeUrl( queryMap[queryM[0]] = URLEncoder.encode(value, "UTF-8") } } else if (charset == "escape") { -// queryMap[queryM[0]] = StringUtils.escape(value) + queryMap[queryM[0]] = Encoder.escape(value) } else { queryMap[queryM[0]] = URLEncoder.encode(value, charset) } @@ -168,14 +171,6 @@ class AnalyzeUrl( return SCRIPT_ENGINE.eval(jsStr, bindings) } - fun getQueryMap(): Map { - return queryMap - } - - fun getHeaderMap(): Map { - return headerMap - } - enum class Method { GET, POST } diff --git a/app/src/main/java/io/legado/app/utils/Encoder.kt b/app/src/main/java/io/legado/app/utils/Encoder.kt new file mode 100644 index 000000000..b74266fa3 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/Encoder.kt @@ -0,0 +1,29 @@ +package io.legado.app.utils + +object Encoder { + + fun escape(src: String): String { + var i = 0 + var char: Char + val tmp = StringBuilder() + tmp.ensureCapacity(src.length * 6) + while (i < src.length) { + char = src[i] + if (Character.isDigit(char) || Character.isLowerCase(char) + || Character.isUpperCase(char) + ) + tmp.append(char) + else if (char.toInt() < 256) { + tmp.append("%") + if (char.toInt() < 16) + tmp.append("0") + tmp.append(char.toInt().toString(16)) + } else { + tmp.append("%u") + tmp.append(char.toInt().toString(16)) + } + i++ + } + return tmp.toString() + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/pop_keyboard_tool.xml b/app/src/main/res/layout/pop_keyboard_tool.xml index d76d3f944..f617d5dfc 100644 --- a/app/src/main/res/layout/pop_keyboard_tool.xml +++ b/app/src/main/res/layout/pop_keyboard_tool.xml @@ -97,6 +97,30 @@ android:textSize="14sp" tools:ignore="HardcodedText" /> + + + + + +