Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions guides/migrating_to_1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ iex> Application.put_env(:safeurl, :detailed_error, false)
iex> SafeURL.validate("http://localhost")
{:error, :restricted}
```

### Change modules implementing `SafeURL.DNSResolver` behaviour

If you have a module that implements `SafeURL.DNSResolver` behaviour, note that
`DNSResolver.resolve/1` signature has changed. Specifically, the ok tuple should now
always return a list of IPs. A single IP is not a valid return type:

```elixir
# DNS is the default implementation
iex> DNS.resolve("wikipedia.org")
{:ok, [{198, 35, 26, 96}]}
```
3 changes: 1 addition & 2 deletions lib/safeurl/dns_resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ defmodule SafeURL.DNSResolver do

"""

@type resolution :: :inet.ip() | [:inet.ip()]
@callback resolve(host :: binary()) :: {:ok, resolution()} | {:error, atom()}
@callback resolve(host :: String.t()) :: {:ok, list()} | {:error, :inet_res.res_error()}
end
2 changes: 1 addition & 1 deletion lib/safeurl/safeurl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ defmodule SafeURL do
{:error, :einval} ->
# TODO: safely handle multiple IPs/round-robin DNS
case dns_module.resolve(hostname) do
{:ok, ips} -> ips |> List.wrap() |> List.first()
{:ok, [ip | _]} -> ip
{:error, _reason} -> nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule SafeURL.MixProject do
[
{:httpoison, "~> 1.0 or ~> 2.0", optional: true},
{:inet_cidr, "~> 1.0 and >= 1.0.6"},
{:dns, "~> 2.2"},
{:dns, "~> 2.4"},
{:tesla, "~> 1.0", optional: true},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
Expand Down
Loading