diff options
author | Allan Wang <me@allanwang.ca> | 2020-05-23 17:53:50 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2020-05-23 17:53:50 -0700 |
commit | aaca5878d5ac84b27917bbf1b7994fe59733fc97 (patch) | |
tree | 6c7d9e12b492153eee3a6afa9884dbc18613af5f /app/src/main/kotlin | |
parent | 000699d73c55cf6bfd5e03fc3f1b24daa21dd111 (diff) | |
download | frost-aaca5878d5ac84b27917bbf1b7994fe59733fc97.tar.gz frost-aaca5878d5ac84b27917bbf1b7994fe59733fc97.tar.bz2 frost-aaca5878d5ac84b27917bbf1b7994fe59733fc97.zip |
Query encode
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt | 15 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt | 3 |
2 files changed, 9 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt index 5ae6856b..093c8c94 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt @@ -18,6 +18,7 @@ package com.pitchedapps.frost.facebook import android.net.Uri import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.urlEncode import java.net.URLDecoder import java.nio.charset.StandardCharsets @@ -89,21 +90,19 @@ class FbUrlFormatter(url: String) { return cleanedUrl } - override fun toString(): String { - val builder = StringBuilder() - builder.append(cleaned) + override fun toString(): String = buildString { + append(cleaned) if (queries.isNotEmpty()) { - builder.append("?") + append("?") queries.forEach { (k, v) -> if (v.isEmpty()) { - builder.append("$k&") + append("${k.urlEncode()}&") } else { - builder.append("$k=$v&") + append("${k.urlEncode()}=${v.urlEncode()}&") } } } - return builder.removeSuffix("&").toString() - } + }.removeSuffix("&") fun toLogList(): List<String> { val list = mutableListOf(cleaned) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt index 28b4a556..42a6ab53 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt @@ -23,6 +23,7 @@ import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.facebook.parsers.FrostSearch.Companion.create import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.urlEncode import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -31,7 +32,7 @@ import org.jsoup.nodes.Element */ object SearchParser : FrostParser<FrostSearches> by SearchParserImpl() { fun query(cookie: String?, input: String): ParseResponse<FrostSearches>? { - val url = "${FbItem._SEARCH_PARSE.url}?q=${if (input.isNotBlank()) input else "a"}" + val url = "${FbItem._SEARCH_PARSE.url}/?q=${if (input.isNotBlank()) input.urlEncode() else "a"}" L._i { "Search Query $url" } return parseFromUrl(cookie, url) } |