Skip to content

Commit

Permalink
Fix raw_html to not encode "title" tags (#555)
Browse files Browse the repository at this point in the history
* raw_html treats the content of title tags as plain text

* change test to avoid differences between parsers
  • Loading branch information
aymanosman authored Mar 23, 2024
1 parent b98dc57 commit d1fd549
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/floki/raw_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ defmodule Floki.RawHTML do
case type do
"script" -> @no_encoder
"style" -> @no_encoder
"title" -> @no_encoder
_ -> encoder
end

Expand Down
6 changes: 6 additions & 0 deletions test/floki_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ defmodule FlokiTest do
assert recombined
end

test "raw_html treats the contents of title tags as plain text" do
html_string = ~s(<html><head><title> <b> bold </b> text </title></head><body></body></html>)
parsed = Floki.parse_document!(html_string)
assert ^html_string = Floki.raw_html(parsed)
end

# Floki.find/2 - Classes

test "find elements with a given class" do
Expand Down

0 comments on commit d1fd549

Please sign in to comment.