diff --git a/lib/phoenix_html/safe.ex b/lib/phoenix_html/safe.ex
index 9118abe..5c01277 100644
--- a/lib/phoenix_html/safe.ex
+++ b/lib/phoenix_html/safe.ex
@@ -45,39 +45,36 @@ defimpl Phoenix.HTML.Safe, for: DateTime do
end
defimpl Phoenix.HTML.Safe, for: List do
- def to_iodata([h | t]) do
- [to_iodata(h) | to_iodata(t)]
- end
+ def to_iodata(list), do: recur(list)
- def to_iodata([]) do
- []
- end
+ defp recur([h | t]), do: [recur(h) | recur(t)]
+ defp recur([]), do: []
- def to_iodata(?<), do: "<"
- def to_iodata(?>), do: ">"
- def to_iodata(?&), do: "&"
- def to_iodata(?"), do: """
- def to_iodata(?'), do: "'"
+ defp recur(?<), do: "<"
+ defp recur(?>), do: ">"
+ defp recur(?&), do: "&"
+ defp recur(?"), do: """
+ defp recur(?'), do: "'"
- def to_iodata(h) when is_integer(h) and h <= 255 do
+ defp recur(h) when is_integer(h) and h <= 255 do
h
end
- def to_iodata(h) when is_integer(h) do
+ defp recur(h) when is_integer(h) do
raise ArgumentError,
"lists in Phoenix.HTML templates only support iodata, and not chardata. Integers may only represent bytes. " <>
"It's likely you meant to pass a string with double quotes instead of a char list with single quotes."
end
- def to_iodata(h) when is_binary(h) do
+ defp recur(h) when is_binary(h) do
Phoenix.HTML.Engine.html_escape(h)
end
- def to_iodata({:safe, data}) do
+ defp recur({:safe, data}) do
data
end
- def to_iodata(other) do
+ defp recur(other) do
raise ArgumentError,
"lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, " <>
"got invalid entry: #{inspect(other)}"