Skip to content

Commit 3116115

Browse files
dmsnellsirreal
andcommitted
Fix tests and fix algorithm
Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
1 parent fe11ad9 commit 3116115

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,15 +764,21 @@ private function step_in_body() {
764764
case '+LI':
765765
$this->state->frameset_ok = false;
766766
$node = $this->state->stack_of_open_elements->current_node();
767+
$is_li = 'LI' === $tag_name;
767768

768769
in_body_list_loop:
769-
if ( $tag_name === $node->node_name ) {
770-
$this->generate_implied_end_tags();
771-
if ( $tag_name !== $this->state->stack_of_open_elements->current_node()->node_name ) {
770+
/*
771+
* The logic for LI and DT/DD is the same except for one point: LI elements _only_
772+
* close other LI elements, but a DT or DD element closes _any_ open DT or DD element.
773+
*/
774+
if ( $is_li ? 'LI' === $node->node_name : ( 'DD' === $node->node_name || 'DT' === $node->node_name ) ) {
775+
$node_name = $is_li ? 'LI' : $node->node_name;
776+
$this->generate_implied_end_tags( $node_name );
777+
if ( $node_name !== $this->state->stack_of_open_elements->current_node()->node_name ) {
772778
// @TODO: Indicate a parse error once it's possible. This error does not impact the logic here.
773779
}
774780

775-
$this->state->stack_of_open_elements->pop_until( $tag_name );
781+
$this->state->stack_of_open_elements->pop_until( $node_name );
776782
goto in_body_list_done;
777783
}
778784

tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ public function data_html_target_with_breadcrumbs() {
363363
'LI after unclosed LI' => array( '<li>one<li>two<li target>three', array( 'HTML', 'BODY', 'LI' ), 3 ),
364364
'LI in UL in LI' => array( '<ul><li>one<ul><li target>two', array( 'HTML', 'BODY', 'UL', 'LI', 'UL', 'LI' ), 1 ),
365365

366-
'DD and DT mutually close, LI self-closes (dt 2)' => array( '<dd><dd><dt><dt target><dd><li><li>', array( 'HTML', 'BODY', 'DT' ), 1 ),
367-
'DD and DT mutually close, LI self-closes (dd 3)' => array( '<dd><dd><dt><dt><dd target><li><li>', array( 'HTML', 'BODY', 'DD' ), 1 ),
366+
'DD and DT mutually close, LI self-closes (dt 2)' => array( '<dd><dd><dt><dt target><dd><li><li>', array( 'HTML', 'BODY', 'DT' ), 2 ),
367+
'DD and DT mutually close, LI self-closes (dd 3)' => array( '<dd><dd><dt><dt><dd target><li><li>', array( 'HTML', 'BODY', 'DD' ), 3 ),
368368
'DD and DT mutually close, LI self-closes (li 1)' => array( '<dd><dd><dt><dt><dd><li target><li>', array( 'HTML', 'BODY', 'DD', 'LI' ), 1 ),
369-
'DD and DT mutually close, LI self-closes (li 2)' => array( '<dd><dd><dt><dt><dd><li><li target>', array( 'HTML', 'BODY', 'DD', 'LI' ), 1 ),
369+
'DD and DT mutually close, LI self-closes (li 2)' => array( '<dd><dd><dt><dt><dd><li><li target>', array( 'HTML', 'BODY', 'DD', 'LI' ), 2 ),
370370
);
371371
}
372372

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Unit tests covering WP_HTML_Processor compliance with HTML5 semantic parsing rules
4+
* for the LI list item element.
5+
*
6+
* @package WordPress
7+
* @subpackage HTML-API
8+
*
9+
* @since 6.5.0
10+
*
11+
* @group html-api
12+
*
13+
* @coversDefaultClass WP_HTML_Processor
14+
*/
15+
class Tests_HtmlApi_WpHtmlProcessorSemanticRulesLIElements extends WP_UnitTestCase {
16+
/*******************************************************************
17+
* RULES FOR "IN BODY" MODE
18+
*******************************************************************/
19+
20+
}

0 commit comments

Comments
 (0)