From 1489f5f5f3e4927a8e0063354b1c59c7199f1353 Mon Sep 17 00:00:00 2001 From: Yuri Pereira Constante Date: Fri, 12 Jan 2024 14:48:26 -0300 Subject: [PATCH] Fix pretty raw_html with encoded text (#525) * Fix pretty raw_html with encoded text * Fix test on html5ever --- lib/floki/raw_html.ex | 9 ++++++--- test/floki_test.exs | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/floki/raw_html.ex b/lib/floki/raw_html.ex index 67993013..f57f453d 100644 --- a/lib/floki/raw_html.ex +++ b/lib/floki/raw_html.ex @@ -219,10 +219,13 @@ defmodule Floki.RawHTML do defp leftpad(:noop), do: "" defp leftpad(%{pad: pad}), do: pad - defp leftpad_content(:noop, string), do: string + defp leftpad_content(:noop, content), do: content - defp leftpad_content(padding, string) do - trimmed = String.trim(string) + defp leftpad_content(padding, content) do + trimmed = + content + |> IO.iodata_to_binary() + |> String.trim() if trimmed == "" do "" diff --git a/test/floki_test.exs b/test/floki_test.exs index 9ff30e28..b9a1f158 100644 --- a/test/floki_test.exs +++ b/test/floki_test.exs @@ -484,6 +484,10 @@ defmodule FlokiTest do
+ encoded content + & + ' + " @@ -517,6 +521,10 @@ defmodule FlokiTest do
+ encoded content + & + ' + " very deep content