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 5ae6856b0..093c8c94b 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 { 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 28b4a5562..42a6ab537 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 by SearchParserImpl() { fun query(cookie: String?, input: String): ParseResponse? { - 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) } diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt index bdb747566..433fdb2a9 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt @@ -163,6 +163,13 @@ class FbUrlTest { assertFbFormat(expected, url) } + @Test + fun queryUrlEncode() { + val url = "${ FB_URL_BASE}sample/?q=#foo" + val expected = "${ FB_URL_BASE}sample/?q=%23foo" + assertFbFormat(expected, url) + } + // @Test // fun viewFullImageIndirect() { // val urlBase = "photo/view_full_size/?fbid=1234&ref_component=mbasic_photo_permalink&ref_page=%2Fwap%2Fphoto.php&refid=13&_ft_=qid.1234%3Amf_story_key.1234%3Atop_level_post_id" diff --git a/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt b/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt index 85de8f893..ac6068eff 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt @@ -56,4 +56,9 @@ class UrlTests { assertFalse(GOOGLE.isFacebookUrl, "google") assertTrue(FACEBOOK_COM.isFacebookUrl, "facebook") } + + @Test + fun queryEncoding() { + assertEquals("%23foo", "#foo".urlEncode()) + } }