Skip to content

Commit

Permalink
Fix pretty raw_html with encoded text (#525)
Browse files Browse the repository at this point in the history
* Fix pretty raw_html with encoded text

* Fix test on html5ever
  • Loading branch information
ypconstante authored Jan 12, 2024
1 parent b01543a commit 1489f5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/floki/raw_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
""
Expand Down
8 changes: 8 additions & 0 deletions test/floki_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ defmodule FlokiTest do
<div class="content">
<span>
<div>
encoded content
&
'
"
<span>
<small>
Expand Down Expand Up @@ -517,6 +521,10 @@ defmodule FlokiTest do
<div class="content">
<span>
<div>
encoded content
&amp;
&#39;
&quot;
<span>
<small>
very deep content
Expand Down

0 comments on commit 1489f5f

Please sign in to comment.