ObjectValidators.Types.ObjectID: Fix when URI.parse returns %URL{host: ""}

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-04-09 04:36:39 +02:00
parent 90cbf55236
commit c401b00c78
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE

View file

@ -6,14 +6,10 @@ def type, do: :string
def cast(object) when is_binary(object) do def cast(object) when is_binary(object) do
# Host has to be present and scheme has to be an http scheme (for now) # Host has to be present and scheme has to be an http scheme (for now)
case URI.parse(object) do case URI.parse(object) do
%URI{host: nil} -> %URI{host: nil} -> :error
:error %URI{host: ""} -> :error
%URI{scheme: scheme} when scheme in ["https", "http"] -> {:ok, object}
%URI{scheme: scheme} when scheme in ["https", "http"] -> _ -> :error
{:ok, object}
_ ->
:error
end end
end end