优化:放宽UrlUrlScheme的正则校验限制 #431

This commit is contained in:
pppscn 2024-03-20 10:00:57 +08:00
parent 275c2667c1
commit b02c03a092

View File

@ -226,31 +226,19 @@ class CommonUtils private constructor() {
}
//是否合法的url
fun checkUrl(urls: String?): Boolean {
return checkUrl(urls, false)
}
fun checkUrl(url: String?, emptyResult: Boolean = false): Boolean {
if (url.isNullOrEmpty()) return emptyResult
//是否合法的url
fun checkUrl(urls: String?, emptyResult: Boolean): Boolean {
if (TextUtils.isEmpty(urls)) return emptyResult
val regex = """^(https?://)?(?:www\.)?(?:\[[a-fA-F0-9:]+\]|[a-zA-Z0-9-]+\.?)(?::\d{1,5})?(?:[-a-zA-Z0-9()@:%_\+.~#?&/=\[\]]*)?${'$'}"""
val pat = Pattern.compile(regex)
val mat = pat.matcher(urls?.trim() ?: "")
return mat.matches()
val regex = Regex("^https?://\\S+\$")
return regex.matches(url)
}
//是否合法的URL Scheme
fun checkUrlScheme(urls: String?): Boolean {
return checkUrlScheme(urls, false)
}
fun checkUrlScheme(url: String?, emptyResult: Boolean = false): Boolean {
if (url.isNullOrEmpty()) return emptyResult
//是否合法的URL Scheme
fun checkUrlScheme(urls: String?, emptyResult: Boolean): Boolean {
if (TextUtils.isEmpty(urls)) return emptyResult
val regex = "^[a-zA-Z\\d]+://[-a-zA-Z\\d+&@#/%?=~_|!:,.;\\[\\]]*[-a-zA-Z\\d+&@#/%=~_|\\[\\]]"
val pat = Pattern.compile(regex)
val mat = pat.matcher(urls?.trim() ?: "")
return mat.matches()
val regex = Regex("^[a-zA-Z\\d]+://\\S+\$")
return regex.matches(url)
}
//是否合法的IP地址
@ -282,6 +270,11 @@ class CommonUtils private constructor() {
return pattenPort.matcher(port).matches()
}
fun checkEmail(email: String): Boolean {
val emailRegex = Regex("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\$")
return emailRegex.matches(email)
}
//是否启用通知监听服务
fun isNotificationListenerServiceEnabled(context: Context): Boolean {
val packageNames = NotificationManagerCompat.getEnabledListenerPackages(context)