Adding checks for subscription url

This commit is contained in:
2dust
2024-10-21 14:25:05 +08:00
parent c4847eb3de
commit e5aba5d99b
4 changed files with 17 additions and 7 deletions

View File

@@ -60,8 +60,6 @@ object AppConfig {
const val CACHE_KEYWORD_FILTER = "cache_keyword_filter"
/** Protocol identifiers. */
const val PROTOCOL_HTTP: String = "http://"
const val PROTOCOL_HTTPS: String = "https://"
const val PROTOCOL_FREEDOM: String = "freedom"
/** Broadcast actions. */

View File

@@ -81,10 +81,10 @@ class SubEditActivity : BaseActivity() {
toast(R.string.sub_setting_remarks)
return false
}
// if (TextUtils.isEmpty(subItem.url)) {
// toast(R.string.sub_setting_url)
// return false
// }
if (!Utils.isValidSubUrl(subItem.url)) {
toast(R.string.toast_invalid_url)
return false
}
MmkvManager.encodeSubscription(editSubId, subItem)
toast(R.string.toast_success)

View File

@@ -219,7 +219,7 @@ object AngConfigManager {
var count = 0
servers.lines()
.forEach { str ->
if (str.startsWith(AppConfig.PROTOCOL_HTTP) || str.startsWith(AppConfig.PROTOCOL_HTTPS)) {
if (Utils.isValidSubUrl(str)) {
count += importUrlAsSubscription(str)
}
}

View File

@@ -465,5 +465,17 @@ object Utils {
// if the program gets here, no port in the range was found
throw IOException("no free port found")
}
fun isValidSubUrl(value: String?): Boolean {
try {
if (value.isNullOrEmpty()) return false
if (URLUtil.isHttpsUrl(value)) return true
if (URLUtil.isHttpUrl(value) && value.contains(LOOPBACK)) return true
} catch (e: Exception) {
e.printStackTrace()
}
return false
}
}