Skip to content

Commit

Permalink
Adding checks for subscription url
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 21, 2024
1 parent c4847eb commit e5aba5d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 0 additions & 2 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
12 changes: 12 additions & 0 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

0 comments on commit e5aba5d

Please sign in to comment.