mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-02 17:07:41 +08:00
修复:错误的 URL 有效性验证正则表达式(兼容IPv6) #286
This commit is contained in:
parent
132dcd808c
commit
26bd64a1e2
@ -215,7 +215,7 @@ class CommonUtils private constructor() {
|
||||
//是否合法的url
|
||||
fun checkUrl(urls: String?, emptyResult: Boolean): Boolean {
|
||||
if (TextUtils.isEmpty(urls)) return emptyResult
|
||||
val regex = "^https?://(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user