fix: string sanitizer
This commit is contained in:
parent
2c521b4ac6
commit
ac531cd3e8
1 changed files with 20 additions and 4 deletions
|
@ -81,7 +81,7 @@ class AnilistMutations {
|
|||
}
|
||||
|
||||
suspend fun postActivity(text:String): String {
|
||||
val encodedText = Gson().toJson(text)
|
||||
val encodedText = text.stringSanitizer()
|
||||
val query = "mutation{SaveTextActivity(text:$encodedText){siteUrl}}"
|
||||
val result = executeQuery<JsonObject>(query)
|
||||
val errors = result?.get("errors")
|
||||
|
@ -90,8 +90,8 @@ class AnilistMutations {
|
|||
}
|
||||
|
||||
suspend fun postReview(summary: String, body: String, mediaId: Int, score: Int): String {
|
||||
val encodedSummary = Gson().toJson(summary)
|
||||
val encodedBody = Gson().toJson(body)
|
||||
val encodedSummary = summary.stringSanitizer()
|
||||
val encodedBody = body.stringSanitizer()
|
||||
val query = "mutation{SaveReview(mediaId:$mediaId,summary:$encodedSummary,body:$encodedBody,score:$score){siteUrl}}"
|
||||
val result = executeQuery<JsonObject>(query)
|
||||
val errors = result?.get("errors")
|
||||
|
@ -100,11 +100,27 @@ class AnilistMutations {
|
|||
}
|
||||
|
||||
suspend fun postReply(activityId: Int, text: String): String {
|
||||
val encodedText = Gson().toJson(text)
|
||||
val encodedText = text.stringSanitizer()
|
||||
val query = "mutation{SaveActivityReply(activityId:$activityId,text:$encodedText){id}}"
|
||||
val result = executeQuery<JsonObject>(query)
|
||||
val errors = result?.get("errors")
|
||||
return errors?.toString()
|
||||
?: (currContext()?.getString(ani.dantotsu.R.string.success) ?: "Success")
|
||||
}
|
||||
|
||||
private fun String.stringSanitizer(): String {
|
||||
val sb = StringBuilder()
|
||||
var i = 0
|
||||
while (i < this.length) {
|
||||
val codePoint = this.codePointAt(i)
|
||||
if (codePoint > 0xFFFF) {
|
||||
sb.append("&#").append(codePoint).append(";")
|
||||
i += 2
|
||||
} else {
|
||||
sb.append(this[i])
|
||||
i++
|
||||
}
|
||||
}
|
||||
return Gson().toJson(sb.toString())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue