mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Prevent invalid user agent header values from being set
Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
parent
e9087583a0
commit
0572287693
3 changed files with 22 additions and 10 deletions
|
@ -54,6 +54,7 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.Headers
|
||||
import rikka.sui.Sui
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
|
@ -274,6 +275,14 @@ class SettingsAdvancedController : SettingsController() {
|
|||
titleRes = R.string.user_agent_string
|
||||
|
||||
onChange {
|
||||
it as String
|
||||
try {
|
||||
// OkHttp checks for valid values internally
|
||||
Headers.Builder().add("User-Agent", it)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
context.toast(R.string.error_user_agent_string_invalid)
|
||||
return@onChange false
|
||||
}
|
||||
activity?.toast(R.string.requires_app_restart)
|
||||
true
|
||||
}
|
||||
|
|
|
@ -40,11 +40,13 @@ class EditTextResetPreference @JvmOverloads constructor(
|
|||
textView?.append(sharedPreferences?.getString(key, defValue))
|
||||
this.setView(view)
|
||||
this.setNeutralButton(R.string.reset) { _, _ ->
|
||||
if (callChangeListener(defValue)) {
|
||||
sharedPreferences?.edit { remove(key) }
|
||||
callChangeListener(defValue)
|
||||
notifyChanged()
|
||||
}
|
||||
}
|
||||
this.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
if (callChangeListener(textView.text.toString())) {
|
||||
sharedPreferences?.edit {
|
||||
if (textView.text.isNullOrBlank()) {
|
||||
remove(key)
|
||||
|
@ -52,9 +54,9 @@ class EditTextResetPreference @JvmOverloads constructor(
|
|||
putString(key, textView.text.toString())
|
||||
}
|
||||
}
|
||||
callChangeListener(textView.text.toString())
|
||||
notifyChanged()
|
||||
}
|
||||
}
|
||||
a.recycle()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -808,6 +808,7 @@
|
|||
<string name="network">Network</string>
|
||||
<string name="doh">DNS over HTTPS</string>
|
||||
<string name="user_agent_string">Default user agent string</string>
|
||||
<string name="error_user_agent_string_invalid">Invalid user agent string</string>
|
||||
<string name="disabled">Disabled</string>
|
||||
<string name="cloudflare" translatable="false">Cloudflare</string>
|
||||
<string name="google" translatable="false">Google</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue