diff --git a/moli-parser/src/html.rs b/moli-parser/src/html.rs index 1fc95e0954..fe46a84f77 100644 --- a/moli-parser/src/html.rs +++ b/moli-parser/src/html.rs @@ -1962,6 +1962,77 @@ mod tests { "plain annotation-xml must not opt into HTML integration point parsing" ); } + #[test] + fn customizable_select_preserves_option_wrapper_elements() { + let document = parse_test_document(concat!( + "", + "" + )); + let select = first_element_by_ns(&document, HTML_NS, "select"); + let divs = document.elements_by_tag_name_ns( + document.document_node_id(), + Some(HTML_NS), + "div", + true, + ); + let wrapper = divs + .iter() + .copied() + .find(|handle| document.get_attribute(*handle, "id").as_deref() == Some("wrapper")) + .expect("select wrapper div"); + let nested = divs + .iter() + .copied() + .find(|handle| document.get_attribute(*handle, "id").as_deref() == Some("nested")) + .expect("nested select wrapper div"); + + assert_eq!( + document + .node(wrapper) + .and_then(|node| node.parent_node_id()), + Some(select) + ); + assert_eq!( + document.node(nested).and_then(|node| node.parent_node_id()), + Some(wrapper) + ); + assert_eq!(document.select_option_elements(select).len(), 3); + + let fragment = HtmlParser::SCRIPTING_ENABLED.parse_fragment( + Url::parse("https://example.test/").expect("test url"), + HTML_NS, + "select", + "
".to_owned(), + ); + let fragment_wrapper = first_element_by_ns(&fragment, HTML_NS, "div"); + let fragment_option = first_element_by_ns(&fragment, HTML_NS, "option"); + assert_eq!( + fragment + .node(fragment_option) + .and_then(|node| node.parent_node_id()), + Some(fragment_wrapper), + "select innerHTML parsing should preserve option wrapper elements" + ); + } + + #[test] + fn decoded_parser_continues_after_meta_encoding_indicator() { + let document = parse_test_document(concat!( + "", + "
" + )); + let div = first_element_by_ns(&document, HTML_NS, "div"); + + assert_eq!( + document.get_attribute(div, "id").as_deref(), + Some("after-meta") + ); + } + #[test] fn parser_input_session_keeps_nested_pending_buffers_on_a_stack() { let queue = ParserInputQueue::default();