From 91208209d5990ff1b6c58bd23b6bc5241b27bc1e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 30 Oct 2024 22:19:37 +0100 Subject: [PATCH] Relax selector parsing Neither the proposal nor the test changes are merged yet. Also, the tests are still failing. https://github.com/html5lib/html5lib-tests/pull/178 https://github.com/whatwg/html/pull/10557 --- html5ever/src/tree_builder/mod.rs | 11 +- html5ever/src/tree_builder/rules.rs | 166 ++++++------------------- html5ever/src/tree_builder/tag_sets.rs | 7 +- html5ever/src/tree_builder/types.rs | 2 - rcdom/html5lib-tests | 2 +- rcdom/tests/html-tree-builder.rs | 9 +- 6 files changed, 47 insertions(+), 150 deletions(-) diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index 348c211d..b6d5a039 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -1146,6 +1146,7 @@ where n } + /// Pop element until an element with the given name has been popped. fn pop_until_named(&self, name: LocalName) -> usize { self.pop_until(|p| *p.ns == ns!(html) && *p.local == name) } @@ -1231,16 +1232,6 @@ where _ => continue, }; match *name { - local_name!("select") => { - for ancestor in self.open_elems.borrow()[0..i].iter().rev() { - if self.html_elem_named(ancestor, local_name!("template")) { - return InSelect; - } else if self.html_elem_named(ancestor, local_name!("table")) { - return InSelectInTable; - } - } - return InSelect; - }, local_name!("td") | local_name!("th") => { if !last { return InCell; diff --git a/html5ever/src/tree_builder/rules.rs b/html5ever/src/tree_builder/rules.rs index 9bce3570..060915d1 100644 --- a/html5ever/src/tree_builder/rules.rs +++ b/html5ever/src/tree_builder/rules.rs @@ -624,6 +624,13 @@ where tag @
=> { self.close_p_element_in_button_scope(); + if self.in_scope_named(default_scope, local_name!("select")) { + self.generate_implied_end_except(local_name!("optgroup")); + if self.in_scope_named(default_scope, local_name!("option")) { + self.sink.parse_error(Borrowed("hr in option")); + } + } + self.insert_and_pop_element_for(tag); self.frameset_ok.set(false); DoneAckSelfClosing @@ -662,28 +669,50 @@ where //