Skip to content

Fix form file input normalized value #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/phoenix_html/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ defmodule Phoenix.HTML.Form do
won't be ignored on submission. This requires however
that the textarea is rendered with no spaces after its
content

* For "file", it returns an empty string because file path
can't be set programmatically.
"""
def normalize_value("datetime-local", %struct{} = value)
when struct in [NaiveDateTime, DateTime] do
Expand All @@ -268,6 +271,10 @@ defmodule Phoenix.HTML.Form do
html_escape(value) == {:safe, "true"}
end

def normalize_value("file", _value) do
""
end

def normalize_value(_type, value) do
value
end
Expand Down
4 changes: 4 additions & 0 deletions test/phoenix_html/form_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ defmodule Phoenix.HTML.FormTest do
assert safe_to_string(normalize_value("textarea", nil)) == "\n"
end

test "for file" do
assert normalize_value("file", "<any>") == ""
end

test "for anything else" do
assert normalize_value("foo", "<other>") == "<other>"
end
Expand Down