You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You might consider trying to use the URL class to do a bit more validation - here's the solution I came up with since I needed something right away:
fun String.isWebsite(): Boolean {
return try {
val url = URL(this)
return url.host.isNotEmpty() && url.protocol.startsWith("http")
} catch (e: Throwable) {
false
}
}
fun <E> Validator<E>.Property<String?>.isWebsite(): Validator<E>.Property<String?> =
this.validate(Website) {
it == null || it.isWebsite()
}
The URL constructor throws an exception for a completely invalid URL, but it accepts some URLs I wouldn't consider valid (eg: http://), and many which we probably wouldn't consider a website (eg: ftp://foo.bar).
For my purposes, I'm considering a website anything which passes the URL parsing, has a host and starts with http.
As noted with test case 5 this solution isn't perfect either but it's close enough for my purposes. I'm not sure if it's appropriate for this library, but maybe it's a helpful starting place if you decide to move forward with this report.
Expected Behavior
Urls like "http://localhost:8000" or ""http://foo.com:8080" pass isWebsite() validator.
Actual Behavior
Any URL with a port or without a domain suffix will fail the regex matching.
Steps to Reproduce the Problem
validate(MyCommand::myUrl).isNotEmpty().isWebsite()
Example Code or Link to a Project
Json Payload
Environment
The text was updated successfully, but these errors were encountered: