Commit 980fa9b7 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Refined the server regex to disallow IP addresses or hosts which contain...

Refined the server regex to disallow IP addresses or hosts which contain multiple dots in succession
parent 79df4cf7
......@@ -53,7 +53,14 @@ class NewServerDialog(
private var validationRegex = SERVER_URL_REGEX
companion object {
private val dohAddressPart = "[a-z0-9][a-z0-9-.]*[a-z0-9]"
// Hostpart has to begin with a character or number
// Then has to either:
// - Consist of numbers, characters and dashes AND ends with a character
// - End with a character or number
// => Host part has to be at least 2 characters long
// Host can optionally end with a dot
// - If there is a dot there has to be either a number or a char after it
private val dohAddressPart = "(?:[a-z0-9](?:(?:[a-z0-9-]*[a-z]*[a-z0-9-]*[a-z0-9])|[a-z0-9])(?:.(?=[a-z0-9])|))*"
val SERVER_URL_REGEX =
Regex(
"^\\s*(?:https://)?((?:$dohAddressPart)|(?:\\[[a-z0-9:]+]))(?::[1-9][0-9]{0,4})?(/[a-z0-9-.]+)*(/)?\\s*$",
......
Supports Markdown
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