envied
envied copied to clipboard
Add url coercer
Our app was recently tripped up because a uri variable was set to server.example.com instead of https://server.example.com (as both can be parsed by URI.parse).
We were using:
variable :SERVER_URL, :uri
but that resulted in:
URI.parse('server.example.com')
=> #<URI::Generic server.example.com>
instead of raising an exception.
So this PR adds a uri_with_scheme coercer to make sure the resulting URI has a scheme eg http for URI:HTTP or https for URI:HTTPS but does not let through a scheme-less uri like URI:Generic.
To be used as:
variable :SERVER_URL, :uri_with_scheme
which will raise an exception unless a valid uri that contains a scheme is used.