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
6 changes: 6 additions & 0 deletions lib/phoenix_html/safe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ defimpl Phoenix.HTML.Safe, for: DateTime do
end
end

if Code.ensure_loaded?(Duration) do
defimpl Phoenix.HTML.Safe, for: Duration do
defdelegate to_iodata(data), to: Duration, as: :to_iso8601
end
end

defimpl Phoenix.HTML.Safe, for: List do
def to_iodata(list), do: recur(list)

Expand Down
7 changes: 7 additions & 0 deletions test/phoenix_html/safe_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ defmodule Phoenix.HTML.SafeTest do
assert Safe.to_iodata(datetime) == "2000-01-01T12:13:14+00:30"
end

if Code.ensure_loaded?(Duration) do
test "impl for Duration" do
duration = Duration.new!(month: 1)
assert Safe.to_iodata(duration) == "P1M"
end
end

test "impl for URI" do
uri = %URI{scheme: "http", host: "www.example.org", path: "/foo", query: "secret=<a&b>"}

Expand Down