diff --git a/app/src/main/kotlin/com/tutpro/baresip/Account.kt b/app/src/main/kotlin/com/tutpro/baresip/Account.kt index e2bf54a5..c04263f9 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Account.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Account.kt @@ -206,13 +206,10 @@ class Account(val accp: String) { fun checkAuthUser(au: String): Boolean { if (au == "") return true val ud = au.split("@") - val userIDRegex = Regex("^([* .!%_`'~]|[+]|[-a-zA-Z0-9]){1,64}\$") - val telnoRegex = Regex("^[+]?[0-9]{1,16}\$") - if (ud.size == 1) { - return userIDRegex.matches(ud[0]) || telnoRegex.matches(ud[0]) - } else { - return (userIDRegex.matches(ud[0]) || telnoRegex.matches(ud[0])) && - Utils.checkDomain(ud[1]) + return when (ud.size) { + 1 -> Utils.checkUriUser(au) + 2 -> Utils.checkUriUser(ud[0]) && Utils.checkDomain(ud[1]) + else -> false } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 435fd7f4..b0da4b1e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -161,8 +161,10 @@ object Utils { checkIpV6(bracketedIp.substring(1, bracketedIp.length - 2)) } - private fun checkUriUser(user: String): Boolean { - user.forEach { if (!(it.isLetterOrDigit() || "-_.!~*\'()&=+\$,;?/".contains(it))) return false } + fun checkUriUser(user: String): Boolean { + val escaped = """%(\d|A|B|C|D|E|F|a|b|c|d|e|f){2}""".toRegex() + escaped.replace(user, "").forEach { + if (!(it.isLetterOrDigit() || "-_.!~*\'()&=+\$,;?/".contains(it))) return false } return user.isNotEmpty() && !checkIpV4(user) && !checkIpV6(user) }