Skip to content

Commit

Permalink
Enable parse of IO data html (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypconstante authored Dec 18, 2023
1 parent e4ea33e commit f229366
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/floki/html_parser/fast_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ defmodule Floki.HTMLParser.FastHtml do

@impl true
def parse_document(html, args) do
execute_with_module(fn module -> module.decode(html, args) end)
execute_with_module(fn module -> module.decode(IO.chardata_to_string(html), args) end)
end

@impl true
def parse_fragment(html, args) do
execute_with_module(fn module -> module.decode_fragment(html, args) end)
execute_with_module(fn module -> module.decode_fragment(IO.chardata_to_string(html), args) end)
end

@impl true
Expand Down
2 changes: 1 addition & 1 deletion lib/floki/html_parser/html5ever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Floki.HTMLParser.Html5ever do
def parse_document(html, _args) do
case Code.ensure_loaded(Html5ever) do
{:module, module} ->
case apply(module, :parse, [html]) do
case apply(module, :parse, [IO.chardata_to_string(html)]) do
{:ok, result} ->
{:ok, result}

Expand Down
2 changes: 1 addition & 1 deletion lib/floki/html_parser/mochiweb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Floki.HTMLParser.Mochiweb do

@impl true
def parse_document(html, args) do
html = "<#{@root_node}>#{html}</#{@root_node}>"
html = ["<#{@root_node}>", html, "</#{@root_node}>"]
{@root_node, _, parsed} = :floki_mochi_html.parse(html, args)

{:ok, parsed}
Expand Down
8 changes: 4 additions & 4 deletions test/floki_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ defmodule FlokiTest do

raw_html = Floki.raw_html(document!(html))

assert raw_html == html
assert raw_html == IO.chardata_to_string(html)

html_with_doctype = [
{:doctype, "html", "", ""},
Expand All @@ -283,7 +283,7 @@ defmodule FlokiTest do

parsed = document!(span_with_entities)

assert Floki.raw_html(parsed) == span_with_entities
assert Floki.raw_html(parsed) == IO.chardata_to_string(span_with_entities)
end

test "raw_html/1 with plain text" do
Expand Down Expand Up @@ -1858,7 +1858,7 @@ defmodule FlokiTest do
end)
|> Floki.raw_html()

assert result == expects
assert result == IO.chardata_to_string(expects)
end

test "changing attribute don't change the order of nodes" do
Expand Down Expand Up @@ -1986,7 +1986,7 @@ defmodule FlokiTest do
end

defp html_body(body) do
"<html><head></head><body>#{body}</body></html>"
["<html><head></head><body>", body, "</body></html>"]
end

defp document!(html_string, opts \\ []) do
Expand Down

0 comments on commit f229366

Please sign in to comment.