Skip to content

Commit 3f23221

Browse files
committed
Ensure matching escapes for nil and empty strings
Closes #444.
1 parent 81782d9 commit 3f23221

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/phoenix_html/engine.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmodule Phoenix.HTML.Engine do
1616
"""
1717
def encode_to_iodata!({:safe, body}), do: body
1818
def encode_to_iodata!(nil), do: ""
19+
def encode_to_iodata!(""), do: ""
1920
def encode_to_iodata!(bin) when is_binary(bin), do: html_escape(bin)
2021
def encode_to_iodata!(list) when is_list(list), do: Phoenix.HTML.Safe.List.to_iodata(list)
2122
def encode_to_iodata!(other), do: Phoenix.HTML.Safe.to_iodata(other)

test/phoenix_html_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ defmodule Phoenix.HTMLTest do
3636
html_escape(~c"foo🐥")
3737
end
3838
end
39+
40+
test "equivalences" do
41+
# Since some HTML code may compare html_escape("") with html_escape(nil),
42+
# we make sure they have equivalent representations.
43+
assert html_escape("") == html_escape(nil)
44+
end
3945
end
4046

4147
describe "attributes_escape" do

0 commit comments

Comments
 (0)