diff options
author | Allan Wang <me@allanwang.ca> | 2020-03-29 19:25:00 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2020-03-29 19:25:00 -0700 |
commit | a51f349c8682ba26ea28a63b845d80a8c2aeeebf (patch) | |
tree | 53524eedf825717c334cbb8fd9b20e365db76ea2 /app | |
parent | b6e1b70e860773f8040dfe5e70bbd88b6d3c7e7c (diff) | |
download | frost-a51f349c8682ba26ea28a63b845d80a8c2aeeebf.tar.gz frost-a51f349c8682ba26ea28a63b845d80a8c2aeeebf.tar.bz2 frost-a51f349c8682ba26ea28a63b845d80a8c2aeeebf.zip |
Encode url query
Diffstat (limited to 'app')
3 files changed, 14 insertions, 3 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index 58e7d629..b3dc58c6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -39,6 +39,7 @@ import android.widget.TextView import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.widget.Toolbar import androidx.core.graphics.alpha +import androidx.core.text.htmlEncode import androidx.core.view.updateLayoutParams import androidx.drawerlayout.widget.DrawerLayout import androidx.fragment.app.Fragment @@ -123,6 +124,7 @@ import com.pitchedapps.frost.utils.launchLogin import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.utils.launchWebOverlay import com.pitchedapps.frost.utils.setFrostColors +import com.pitchedapps.frost.utils.urlEncode import com.pitchedapps.frost.views.BadgedIcon import com.pitchedapps.frost.views.FrostVideoViewer import com.pitchedapps.frost.views.FrostViewPager @@ -131,6 +133,8 @@ import kotlin.math.abs import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import org.koin.android.ext.android.inject +import java.net.URLEncoder +import java.nio.charset.StandardCharsets /** * Created by Allan Wang on 20/12/17. @@ -649,12 +653,13 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, if (items.isNotEmpty()) items.add( SearchItem( - "${FbItem._SEARCH.url}?q=$query", + "${FbItem._SEARCH.url}/?q=${query.urlEncode()}", string(R.string.show_all_results), iicon = null ) ) searchViewCache[query] = items + searchView.results = items } } @@ -663,7 +668,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, searchCallback = { query, _ -> launchWebOverlay( - "${FbItem._SEARCH.url}/?q=$query", + "${FbItem._SEARCH.url}/?q=${query.urlEncode()}", fbCookie, prefs ); true diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt index f754b454..e1a6c814 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt @@ -24,6 +24,7 @@ import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.services.NotificationContent import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.urlEncode import org.apache.commons.text.StringEscapeUtils import org.jsoup.Jsoup import org.jsoup.nodes.Document @@ -39,7 +40,7 @@ import org.jsoup.nodes.Element object MessageParser : FrostParser<FrostMessages> by MessageParserImpl() { fun queryUser(cookie: String?, name: String) = - parseFromUrl(cookie, "${FbItem.MESSAGES.url}/?q=$name") + parseFromUrl(cookie, "${FbItem.MESSAGES.url}/?q=${name.urlEncode()}") } data class FrostMessages( diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index 6db7179d..a8e7c64c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -81,6 +81,8 @@ import org.apache.commons.text.StringEscapeUtils import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import java.net.URLEncoder +import java.nio.charset.StandardCharsets /** * Created by Allan Wang on 2017-06-03. @@ -370,6 +372,9 @@ val dependentSegments = arrayOf( inline val String?.isExplicitIntent get() = this != null && (startsWith("intent://") || startsWith("market://")) +fun String.urlEncode(): String = + URLEncoder.encode(this, StandardCharsets.UTF_8.name()) + fun Context.frostChangelog() = showChangelog(R.xml.frost_changelog) fun Context.frostUriFromFile(file: File): Uri = |