phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.23k stars 934 forks source link

Regression? in raw_html encoding from Phoenix.LiveViewTest.live/2 and latest Floki 0.36.3 #3511

Closed inf-rno closed 5 days ago

inf-rno commented 6 days ago

Environment

Single File Test Script:

```elixir Application.put_env(:phoenix, Example.Endpoint, http: [ip: {127, 0, 0, 1}, port: 5001], server: true, live_view: [signing_salt: "aaaaaaaa"], secret_key_base: String.duplicate("a", 64) ) Mix.install([ {:plug_cowboy, "~> 2.5"}, {:jason, "~> 1.0"}, {:phoenix, "~> 1.7"}, # please test your issue using the latest version of LV from GitHub! {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", branch: "main", override: true}, {:floki, "== 0.36.3"} ]) ExUnit.start() defmodule Example.ErrorView do def render(template, _), do: Phoenix.Controller.status_message_from_template(template) end defmodule Example.HomeLive do use Phoenix.LiveView, layout: {__MODULE__, :live} def mount(_params, _session, socket) do socket |> then(&{:ok, &1}) end def render("live.html", assigns) do ~H""" <%= @inner_content %> """ end def render(assigns) do ~H"""

The LiveView content goes' here

""" end end defmodule Example.Router do use Phoenix.Router import Phoenix.LiveView.Router pipeline :browser do plug(:accepts, ["html"]) end scope "/", Example do pipe_through(:browser) live("/", HomeLive, :index) end end defmodule Example.Endpoint do use Phoenix.Endpoint, otp_app: :phoenix socket("/live", Phoenix.LiveView.Socket) plug(Plug.Static, from: {:phoenix, "priv/static"}, at: "/assets/phoenix") plug(Plug.Static, from: {:phoenix_live_view, "priv/static"}, at: "/assets/phoenix_live_view") plug(Example.Router) end defmodule Example.HomeLiveTest do use ExUnit.Case import Phoenix.ConnTest import Plug.Conn import Phoenix.LiveViewTest @endpoint Example.Endpoint test "works properly" do conn = Phoenix.ConnTest.build_conn() {:ok, _view, html} = live(conn, "/") assert html =~ "The LiveView content goes' here" |> Phoenix.HTML.html_escape() |> Phoenix.HTML.safe_to_string() end end {:ok, _} = Supervisor.start_link([Example.Endpoint], strategy: :one_for_one) ExUnit.run() ```

Actual behavior

The above test fails. The returned html from live/2 is no longer html encoded while using the latest Floki version 0.36.3. Swap the dependency in the script above to use 0.36.2 and it will pass.

Expected behavior

The test passes.

Extra

While trying out a similar test directly with Floki between the two latest versions, the results are similar. e.g.:

Mix.install([
  {:floki, "== 0.36.3"}
])

Floki.raw_html("hello'world")
# outputs: "hello&#39;world"

P.S.: I am new to Elixir and Phoenix, so I might be missing something here but figured I'd create an issue to clarify.

SteffenDE commented 5 days ago

Hi @inf-rno!

LiveView uses Floki under the hood for its testing code, so theres not much we can do here. Please open up an issue in Floki instead :)

inf-rno commented 5 days ago

Hi @inf-rno!

LiveView uses Floki under the hood for its testing code, so theres not much we can do here. Please open up an issue in Floki instead :)

Thanks for the response. I see there's some code changes in their latest release in the related code. But as I've shown the behavior for encoding html hasn't changed. So it looks like there's something in the glue where liveview is calling floki where this breaks?

Nonetheless, this is a behavioral change in liveview with the latest version of floki. So if they turn me around, should we be pinning to the older version instead.