From 33411265811888e7b120c6b8828d7a7d00711c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 6 Oct 2023 12:12:02 +0200 Subject: [PATCH] Depend on latest Plug and use more efficient query decoding --- lib/phoenix_live_view/test/client_proxy.ex | 25 +++++++++++----------- mix.exs | 1 + mix.lock | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/phoenix_live_view/test/client_proxy.ex b/lib/phoenix_live_view/test/client_proxy.ex index c6325e1bb..5c7940739 100644 --- a/lib/phoenix_live_view/test/client_proxy.ex +++ b/lib/phoenix_live_view/test/client_proxy.ex @@ -24,6 +24,7 @@ defmodule Phoenix.LiveViewTest.ClientProxy do connect_params: %{}, connect_info: %{} + alias Plug.Conn.Query alias Phoenix.LiveViewTest.{ClientProxy, DOM, Element, View, Upload} @doc """ @@ -1057,20 +1058,20 @@ defmodule Phoenix.LiveViewTest.ClientProxy do tag == "form" -> defaults = node - |> DOM.reverse_filter(fn node -> + |> DOM.filter(fn node -> DOM.tag(node) in ~w(input textarea select) and is_nil(DOM.attribute(node, "disabled")) end) - |> Enum.reduce(%{}, &form_defaults/2) + |> Enum.reduce(Query.decode_init(), &form_defaults/2) with {:ok, defaults} <- maybe_submitter(defaults, type, node, element), {:ok, value} <- fill_in_map(Enum.to_list(element.form_data || %{}), "", node, []) do - {:ok, DOM.deep_merge(defaults, value)} + {:ok, DOM.deep_merge(Query.decode_done(defaults), value)} else {:error, _, _} = error -> error end type == :change and tag in ~w(input select textarea) -> - {:ok, form_defaults(node, %{})} + {:ok, form_defaults(node, Query.decode_init()) |> Query.decode_done()} true -> {:error, :invalid, "phx-#{type} is only allowed in forms, got #{inspect(tag)}"} @@ -1103,7 +1104,7 @@ defmodule Phoenix.LiveViewTest.ClientProxy do "form submitter selected by #{inspect(element.selector)} must have a name"} submitter?(node) and is_nil(DOM.attribute(node, "disabled")) -> - {:ok, Plug.Conn.Query.decode_pair({name, DOM.attribute(node, "value")}, defaults)} + {:ok, Plug.Conn.Query.decode_each({name, DOM.attribute(node, "value")}, defaults)} true -> {:error, :invalid, @@ -1178,19 +1179,17 @@ defmodule Phoenix.LiveViewTest.ClientProxy do ) end - all_selected - |> Enum.reverse() - |> Enum.reduce(acc, fn selected, acc -> - Plug.Conn.Query.decode_pair({name, DOM.attribute(selected, "value")}, acc) + Enum.reduce(all_selected, acc, fn selected, acc -> + Plug.Conn.Query.decode_each({name, DOM.attribute(selected, "value")}, acc) end) end defp form_defaults({"textarea", _, []}, name, acc) do - Plug.Conn.Query.decode_pair({name, ""}, acc) + Plug.Conn.Query.decode_each({name, ""}, acc) end defp form_defaults({"textarea", _, [value]}, name, acc) do - Plug.Conn.Query.decode_pair({name, String.replace_prefix(value, "\n", "")}, acc) + Plug.Conn.Query.decode_each({name, String.replace_prefix(value, "\n", "")}, acc) end defp form_defaults({"input", _, _} = node, name, acc) do @@ -1200,7 +1199,7 @@ defmodule Phoenix.LiveViewTest.ClientProxy do cond do type in ["radio", "checkbox"] -> if DOM.attribute(node, "checked") do - Plug.Conn.Query.decode_pair({name, value}, acc) + Plug.Conn.Query.decode_each({name, value}, acc) else acc end @@ -1209,7 +1208,7 @@ defmodule Phoenix.LiveViewTest.ClientProxy do acc true -> - Plug.Conn.Query.decode_pair({name, value}, acc) + Plug.Conn.Query.decode_each({name, value}, acc) end end diff --git a/mix.exs b/mix.exs index b02345eaa..db08a4dfc 100644 --- a/mix.exs +++ b/mix.exs @@ -37,6 +37,7 @@ defmodule Phoenix.LiveView.MixProject do defp deps do [ {:phoenix, "~> 1.6.15 or ~> 1.7.0"}, + {:plug, "~> 1.15"}, {:phoenix_view, "~> 2.0", optional: true}, {:phoenix_template, "~> 1.0"}, {:phoenix_html, "~> 3.3"}, diff --git a/mix.lock b/mix.lock index b2d0571f4..165e4a474 100644 --- a/mix.lock +++ b/mix.lock @@ -13,7 +13,7 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"}, "makeup_html": {:hex, :makeup_html, "0.1.0", "b0228fda985e311d8f0d25bed58f8280826633a38d7448cabdd723e116165bcf", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "0ca44e7dcb8d933e010740324470dd8ec947243b51304bd34b8165ef3281edc2"}, - "mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"}, + "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, "nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"}, "phoenix": {:hex, :phoenix, "1.6.15", "0a1d96bbc10747fd83525370d691953cdb6f3ccbac61aa01b4acb012474b047d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d70ab9fbf6b394755ea88b644d34d79d8b146e490973151f248cacd122d20672"}, "phoenix_html": {:hex, :phoenix_html, "3.3.0", "bf451c71ebdaac8d2f40d3b703435e819ccfbb9ff243140ca3bd10c155f134cc", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "272c5c1533499f0132309936c619186480bafcc2246588f99a69ce85095556ef"}, @@ -21,7 +21,7 @@ "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, "phoenix_template": {:hex, :phoenix_template, "1.0.1", "85f79e3ad1b0180abb43f9725973e3b8c2c3354a87245f91431eec60553ed3ef", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "157dc078f6226334c91cb32c1865bf3911686f8bcd6bcff86736f6253e6993ee"}, "phoenix_view": {:hex, :phoenix_view, "2.0.1", "a653e3d9d944aace0a064e4a13ad473ffa68f7bc4ca42dbf83cc1d464f1fb295", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "6c358e2cefc5f341c728914b867c556bbfd239fed9e881bac257d70cb2b8a6f6"}, - "plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"}, - "plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"}, + "plug": {:hex, :plug, "1.15.1", "b7efd81c1a1286f13efb3f769de343236bd8b7d23b4a9f40d3002fc39ad8f74c", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "459497bd94d041d98d948054ec6c0b76feacd28eec38b219ca04c0de13c79d30"}, + "plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, }