diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b0a9208..95c01cfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v2.14.3 (2020-12-12) + +* Bug fixes + * Fix warnings on Elixir v1.12 + ## v2.14.2 (2020-04-30) * Deprecations diff --git a/lib/phoenix_html/engine.ex b/lib/phoenix_html/engine.ex index 9aef613a..9e767c7f 100644 --- a/lib/phoenix_html/engine.ex +++ b/lib/phoenix_html/engine.ex @@ -22,7 +22,7 @@ defmodule Phoenix.HTML.Engine do def encode_to_iodata!(body) when is_binary(body), do: Plug.HTML.html_escape(body) def encode_to_iodata!(other), do: Phoenix.HTML.Safe.to_iodata(other) - @impl true + @doc false def init(_opts) do %{ iodata: [], @@ -31,30 +31,35 @@ defmodule Phoenix.HTML.Engine do } end - @impl true + @doc false def handle_begin(state) do %{state | iodata: [], dynamic: []} end - @impl true + @doc false def handle_end(quoted) do handle_body(quoted) end - @impl true + @doc false def handle_body(state) do %{iodata: iodata, dynamic: dynamic} = state safe = {:safe, Enum.reverse(iodata)} {:__block__, [], Enum.reverse([safe | dynamic])} end - @impl true + @doc false def handle_text(state, text) do + handle_text(state, [], text) + end + + @doc false + def handle_text(state, _meta, text) do %{iodata: iodata} = state %{state | iodata: [text | iodata]} end - @impl true + @doc false def handle_expr(state, "=", ast) do ast = traverse(ast) %{iodata: iodata, dynamic: dynamic, vars_count: vars_count} = state diff --git a/lib/phoenix_html/tag.ex b/lib/phoenix_html/tag.ex index 95d1e1a7..73810cf4 100644 --- a/lib/phoenix_html/tag.ex +++ b/lib/phoenix_html/tag.ex @@ -108,7 +108,7 @@ defmodule Phoenix.HTML.Tag do defp nested_attrs(attr, dict, acc) do Enum.reduce(dict, acc, fn {k, v}, acc -> - attr_name = "#{attr}-#{dasherize(k)}" + attr_name = "#{attr}-#{convert_attribute_name(k)}" case is_list(v) do true -> nested_attrs(attr_name, v, acc) @@ -123,11 +123,11 @@ defmodule Phoenix.HTML.Tag do defp build_attrs(_tag, [], acc), do: acc |> Enum.sort() |> tag_attrs defp build_attrs(tag, [{k, v} | t], acc) when k in @tag_prefixes and is_list(v) do - build_attrs(tag, t, nested_attrs(dasherize(k), v, acc)) + build_attrs(tag, t, nested_attrs(convert_attribute_name(k), v, acc)) end defp build_attrs(tag, [{k, true} | t], acc) do - build_attrs(tag, t, [dasherize(k) | acc]) + build_attrs(tag, t, [convert_attribute_name(k) | acc]) end defp build_attrs(tag, [{_, false} | t], acc) do @@ -139,11 +139,25 @@ defmodule Phoenix.HTML.Tag do end defp build_attrs(tag, [{k, v} | t], acc) do - build_attrs(tag, t, [{dasherize(k), v} | acc]) + build_attrs(tag, t, [{convert_attribute_name(k), v} | acc]) end - defp dasherize(value) when is_atom(value), do: dasherize(Atom.to_string(value)) - defp dasherize(value) when is_binary(value), do: String.replace(value, "_", "-") + defp convert_attribute_name(value) when is_atom(value), do: dasherize(Atom.to_string(value)) + + defp convert_attribute_name(value) when is_binary(value) do + result = dasherize(value) + future_result = Phoenix.HTML.Safe.to_iodata(value) + + if result != future_result do + IO.warn( + "content_tag/tag converts the attribute name '#{value}' to '#{result}' but will convert it to '#{future_result}' in v3" + ) + end + + result + end + + defp dasherize(string), do: String.replace(string, "_", "-") @doc ~S""" Generates a form tag. diff --git a/mix.exs b/mix.exs index d02fca04..d504f403 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule PhoenixHtml.Mixfile do use Mix.Project # Also change package.json version - @version "2.14.2" + @version "2.14.3" def project do [ diff --git a/mix.lock b/mix.lock index 1cda0e27..67b0f55c 100644 --- a/mix.lock +++ b/mix.lock @@ -1,10 +1,11 @@ %{ "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, - "ex_doc": {:hex, :ex_doc, "0.21.3", "857ec876b35a587c5d9148a2512e952e24c24345552259464b98bfbb883c7b42", [:mix], [{:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "0db1ee8d1547ab4877c5b5dffc6604ef9454e189928d5ba8967d4a58a801f161"}, - "makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "a10c6eb62cca416019663129699769f0c2ccf39428b3bb3c0cb38c718a0c186d"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "d4b316c7222a85bbaa2fd7c6e90e37e953257ad196dc229505137c5e505e9eff"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"}, + "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, + "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"}, "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm", "589b5af56f4afca65217a1f3eb3fee7e79b09c40c742fddc1c312b3ac0b3399f"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, "plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm", "daa5fee4209c12c3c48b05a96cf88c320b627c9575f987554dcdc1fdcdf2c15e"}, "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm", "73c1682f0e414cfb5d9b95c8e8cd6ffcfdae699e3b05e1db744e58b7be857759"}, } diff --git a/package.json b/package.json index d72d6079..e7402d6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "phoenix_html", - "version": "2.14.2", + "version": "2.14.3", "main": "./priv/static/phoenix_html.js", "repository": { }, diff --git a/test/phoenix_html/tag_test.exs b/test/phoenix_html/tag_test.exs index 34917dbc..af03fe45 100644 --- a/test/phoenix_html/tag_test.exs +++ b/test/phoenix_html/tag_test.exs @@ -32,6 +32,12 @@ defmodule Phoenix.HTML.TagTest do assert tag(:audio, autoplay: true) |> safe_to_string() == ~s(