@@ -649,6 +649,51 @@ public function test_visits_outer_anchor_virtual_closer_after_mathml_text_integr
649649 );
650650 }
651651
652+ /**
653+ * Ensures that the removed outer A element's virtual closer is visited
654+ * before a new same-name opener immediately following the subtree.
655+ *
656+ * This is the one input where the adjusted-current-node guard and the
657+ * same-name next-event lookahead in the virtual-closer queueing must
658+ * cooperate: the new A opener shares the removed element's tag name, but
659+ * the virtual closer must still fire first so the new element opens as a
660+ * sibling, not a child.
661+ *
662+ * @ticket 61576
663+ *
664+ * @covers WP_HTML_Processor::get_breadcrumbs
665+ * @covers WP_HTML_Processor::is_tag_closer
666+ */
667+ public function test_visits_outer_anchor_virtual_closer_before_same_name_opener () {
668+ $ processor = WP_HTML_Processor::create_fragment ( '<a><math><mi>x<a>y</a></mi></math><a>z ' );
669+
670+ $ visits = array ();
671+ while ( $ processor ->next_tag (
672+ array (
673+ 'tag_name ' => 'A ' ,
674+ 'tag_closers ' => 'visit ' ,
675+ )
676+ ) ) {
677+ $ visits [] = array (
678+ $ processor ->is_tag_closer () ? 'closer ' : 'opener ' ,
679+ $ processor ->get_breadcrumbs (),
680+ );
681+ }
682+
683+ $ this ->assertSame (
684+ array (
685+ array ( 'opener ' , array ( 'HTML ' , 'BODY ' , 'A ' ) ),
686+ array ( 'opener ' , array ( 'HTML ' , 'BODY ' , 'A ' , 'MATH ' , 'MI ' , 'A ' ) ),
687+ array ( 'closer ' , array ( 'HTML ' , 'BODY ' , 'A ' , 'MATH ' , 'MI ' ) ),
688+ array ( 'closer ' , array ( 'HTML ' , 'BODY ' ) ),
689+ array ( 'opener ' , array ( 'HTML ' , 'BODY ' , 'A ' ) ),
690+ array ( 'closer ' , array ( 'HTML ' , 'BODY ' ) ),
691+ ),
692+ $ visits ,
693+ 'Expected the removed outer A virtual closer to be visited before the new same-name A opener. '
694+ );
695+ }
696+
652697 /**
653698 * Ensures that an outer A element removed from the stack of open elements
654699 * remains visitable as a virtual closer when the fragment ends inside its
0 commit comments