diff --git a/native/html5ever_nif/src/flat_dom.rs b/native/html5ever_nif/src/flat_dom.rs index da2eee3..f1d0c8f 100644 --- a/native/html5ever_nif/src/flat_dom.rs +++ b/native/html5ever_nif/src/flat_dom.rs @@ -526,6 +526,8 @@ pub fn flat_sink_to_rec_term<'a>( child_base: 0, child_n: 0, }]; + let mut comments_bf_doctype = 0usize; + let mut read_doctype = false; loop { let mut top = stack.pop().unwrap(); @@ -567,7 +569,9 @@ pub fn flat_sink_to_rec_term<'a>( system_id, } => { assert!(!stack.is_empty()); - assert!(child_stack.is_empty()); + assert!(child_stack.is_empty() || comments_bf_doctype == child_stack.len()); + + read_doctype = true; term = ( atoms::doctype(), @@ -596,6 +600,10 @@ pub fn flat_sink_to_rec_term<'a>( term = StrTendrilWrapper(contents).encode(env); } NodeData::Comment { contents } => { + if !read_doctype { + comments_bf_doctype += 1 + }; + term = (atoms::comment(), StrTendrilWrapper(contents)).encode(env); } _ => unimplemented!(""), diff --git a/test/html5ever_test.exs b/test/html5ever_test.exs index 9fbbae5..44797dc 100644 --- a/test/html5ever_test.exs +++ b/test/html5ever_test.exs @@ -308,4 +308,46 @@ defmodule Html5everTest do ]} ]} end + + test "parse html starting with a XML tag" do + html = """ + + + + +