Skip to content

Commit

Permalink
Fix warnings on Elixir v1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 28, 2024
1 parent b6d63e7 commit 687cca8
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions lib/phoenix_html/safe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: "&lt;"
def to_iodata(?>), do: "&gt;"
def to_iodata(?&), do: "&amp;"
def to_iodata(?"), do: "&quot;"
def to_iodata(?'), do: "&#39;"
defp recur(?<), do: "&lt;"
defp recur(?>), do: "&gt;"
defp recur(?&), do: "&amp;"
defp recur(?"), do: "&quot;"
defp recur(?'), do: "&#39;"

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)}"
Expand Down

0 comments on commit 687cca8

Please sign in to comment.