Skip to content

Commit

Permalink
Convert values to strings on normalize_value
Browse files Browse the repository at this point in the history
Except nils and booleans
  • Loading branch information
josevalim committed Oct 3, 2023
1 parent af43dc0 commit ef01ed3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/phoenix_html/form.ex
Expand Up @@ -248,9 +248,10 @@ defmodule Phoenix.HTML.Form do
html_escape(value) == {:safe, "true"}
end

def normalize_value(_type, value) do
value
end
def normalize_value(_type, nil), do: nil
def normalize_value(_type, true), do: true
def normalize_value(_type, false), do: false
def normalize_value(_type, value), do: html_escape(value)

@doc """
Returns options to be used inside a select.
Expand Down
3 changes: 2 additions & 1 deletion test/phoenix_html/form_test.exs
Expand Up @@ -114,7 +114,8 @@ defmodule Phoenix.HTML.FormTest do
end

test "for anything else" do
assert normalize_value("foo", "<other>") == "<other>"
assert normalize_value("foo", nil) == nil
assert normalize_value("foo", "<other>") == {:safe, [[[] | "&lt;"], "other" | "&gt;"]}
end
end

Expand Down

0 comments on commit ef01ed3

Please sign in to comment.