Skip to content

Commit

Permalink
Fix parsing of comments in parse/1 (#141)
Browse files Browse the repository at this point in the history
Closes #121
  • Loading branch information
philss authored Mar 23, 2024
1 parent af4791f commit 515daa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion native/html5ever_nif/src/flat_dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ pub fn flat_sink_to_rec_term<'a>(
NodeData::Text { contents } => {
term = StrTendrilWrapper(contents).encode(env);
}
NodeData::Comment { .. } => continue,
NodeData::Comment { contents } => {
term = (atoms::comment(), StrTendrilWrapper(contents)).encode(env);
}
_ => unimplemented!(""),
}

Expand Down
12 changes: 10 additions & 2 deletions test/html5ever_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ defmodule Html5everTest do
end

test "parse basic html" do
html = "<html><head></head><body></body></html>"
html = "<html><head></head><body><h1>Hello</h1><!-- my comment --></body></html>"

assert Html5ever.parse(html) == {:ok, [{"html", [], [{"head", [], []}, {"body", [], []}]}]}
assert Html5ever.parse(html) ==
{:ok,
[
{"html", [],
[
{"head", [], []},
{"body", [], [{"h1", [], ["Hello"]}, {:comment, " my comment "}]}
]}
]}
end

test "does not parse with not valid UTF8 binary" do
Expand Down

0 comments on commit 515daa0

Please sign in to comment.