Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pretty raw_html with encoded text #525

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/floki/raw_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,13 @@ defmodule Floki.RawHTML do
defp leftpad(:noop), do: ""
defp leftpad(%{pad: pad, depth: depth}), do: String.duplicate(pad, depth)

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