envied icon indicating copy to clipboard operation
envied copied to clipboard

Add url coercer

Open locochris opened this issue 7 years ago • 0 comments

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.

locochris avatar Mar 23 '18 05:03 locochris