@@ -45,39 +45,36 @@ defimpl Phoenix.HTML.Safe, for: DateTime do
45
45
end
46
46
47
47
defimpl Phoenix.HTML.Safe , for: List do
48
- def to_iodata ( [ h | t ] ) do
49
- [ to_iodata ( h ) | to_iodata ( t ) ]
50
- end
48
+ def to_iodata ( list ) , do: recur ( list )
51
49
52
- def to_iodata ( [ ] ) do
53
- [ ]
54
- end
50
+ defp recur ( [ h | t ] ) , do: [ recur ( h ) | recur ( t ) ]
51
+ defp recur ( [ ] ) , do: [ ]
55
52
56
- def to_iodata ( ?< ) , do: "<"
57
- def to_iodata ( ?> ) , do: ">"
58
- def to_iodata ( ?& ) , do: "&"
59
- def to_iodata ( ?" ) , do: """
60
- def to_iodata ( ?' ) , do: "'"
53
+ defp recur ( ?< ) , do: "<"
54
+ defp recur ( ?> ) , do: ">"
55
+ defp recur ( ?& ) , do: "&"
56
+ defp recur ( ?" ) , do: """
57
+ defp recur ( ?' ) , do: "'"
61
58
62
- def to_iodata ( h ) when is_integer ( h ) and h <= 255 do
59
+ defp recur ( h ) when is_integer ( h ) and h <= 255 do
63
60
h
64
61
end
65
62
66
- def to_iodata ( h ) when is_integer ( h ) do
63
+ defp recur ( h ) when is_integer ( h ) do
67
64
raise ArgumentError ,
68
65
"lists in Phoenix.HTML templates only support iodata, and not chardata. Integers may only represent bytes. " <>
69
66
"It's likely you meant to pass a string with double quotes instead of a char list with single quotes."
70
67
end
71
68
72
- def to_iodata ( h ) when is_binary ( h ) do
69
+ defp recur ( h ) when is_binary ( h ) do
73
70
Phoenix.HTML.Engine . html_escape ( h )
74
71
end
75
72
76
- def to_iodata ( { :safe , data } ) do
73
+ defp recur ( { :safe , data } ) do
77
74
data
78
75
end
79
76
80
- def to_iodata ( other ) do
77
+ defp recur ( other ) do
81
78
raise ArgumentError ,
82
79
"lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, " <>
83
80
"got invalid entry: #{ inspect ( other ) } "
0 commit comments