pull/32/head
kunfei 5 years ago
parent 10b0e1266b
commit be93369a4e
  1. 13
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  2. 29
      app/src/main/java/io/legado/app/utils/Encoder.kt
  3. 24
      app/src/main/res/layout/pop_keyboard_tool.xml

@ -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<Map<String, String>>(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<String, String> {
return queryMap
}
fun getHeaderMap(): Map<String, String> {
return headerMap
}
enum class Method {
GET, POST
}

@ -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()
}
}

@ -97,6 +97,30 @@
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="<"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text=">"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="\"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

Loading…
Cancel
Save