修复错误的 URL 有效性验证正则表达式 (#286)

pull/335/head
Vincent 1 year ago committed by GitHub
parent 17830f10df
commit 0eab5dcaa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -211,7 +211,7 @@ class CommonUtils private constructor() {
//是否合法的url
fun checkUrl(urls: String?, emptyResult: Boolean): Boolean {
if (TextUtils.isEmpty(urls)) return emptyResult
val regex = "^(https?|ftp|file)://[-a-zA-Z\\d+&@#/%?=~_|!:,.;\\[\\]]*[-a-zA-Z\\d+&@#/%=~_|\\[\\]]"
val regex = "^https?://(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"
val pat = Pattern.compile(regex)
val mat = pat.matcher(urls?.trim() ?: "")
return mat.matches()

Loading…
Cancel
Save