Fix domain validator

pull/343/head
Koitharu 3 years ago
parent 648ee3c763
commit 21bcb293f5
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -1,11 +1,14 @@
package org.koitharu.kotatsu.settings
import okhttp3.HttpUrl
import okhttp3.internal.toCanonicalHost
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.utils.EditTextValidator
class DomainValidator : EditTextValidator() {
private val urlBuilder = HttpUrl.Builder()
override fun validate(text: String): ValidationResult {
val trimmed = text.trim()
if (trimmed.isEmpty()) {
@ -18,13 +21,7 @@ class DomainValidator : EditTextValidator() {
}
}
private fun checkCharacters(value: String): Boolean {
for (i in value.indices) {
val c = value[i]
if (c !in '\u0020'..'\u007e') {
return false
}
}
return true
}
private fun checkCharacters(value: String): Boolean = runCatching {
urlBuilder.host(value)
}.isSuccess
}

Loading…
Cancel
Save