Commit 4692efb9 authored by Mygod's avatar Mygod

Be more strict about validating generic template

parent 976c3e4b
......@@ -51,6 +51,7 @@ import java.net.IDN
import java.net.MalformedURLException
import java.net.URL
import java.util.*
import java.util.regex.PatternSyntaxException
class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ActionMode.Callback {
companion object {
......@@ -128,7 +129,15 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
private fun validate(template: Int = templateSelector.selectedItemPosition, value: Editable = editText.text) {
var message = ""
positive.isEnabled = when (Template.values()[template]) {
Template.Generic -> value.isNotEmpty()
Template.Generic -> value.toString().run {
try {
if (Subnet.fromString(this) == null) toPattern()
true
} catch (e: PatternSyntaxException) {
message = e.localizedMessage
false
}
}
Template.Domain -> try {
IDN.toASCII(value.toString(), IDN.ALLOW_UNASSIGNED or IDN.USE_STD3_ASCII_RULES)
true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment